Skip to content

Fix files with dollar signs in names being incorrectly expanded#111

Merged
babarot merged 1 commit intomainfrom
babarot/fix-dollar-sign-filename
Mar 20, 2026
Merged

Fix files with dollar signs in names being incorrectly expanded#111
babarot merged 1 commit intomainfrom
babarot/fix-dollar-sign-filename

Conversation

@babarot
Copy link
Copy Markdown
Owner

@babarot babarot commented Mar 20, 2026

Summary

Fix a bug where files containing $ in their names cannot be trashed because expandPath interprets them as environment variable references.

Background

Reported in Issue #105. When a user runs gomi '$var' (with shell quoting to prevent shell expansion), the expandPath function calls os.ExpandEnv on the path, which resolves $var to its environment variable value (or empty string if unset). This causes the file to either not be found or to silently operate on a wrong path.

Environment variable expansion in file arguments is the shell's responsibility, not the application's. The forbiddenPaths config values (e.g. $HOME/.gomi) are correctly expanded separately in isForbiddenPath, so this change has no side effects.

Changes

  • cli/put.go: Replace the expandPath implementation β€” remove all os.ExpandEnv calls and use filepath.Clean only. File arguments are now treated literally, preserving $ and other special characters in filenames.

Closes #105

Remove environment variable expansion from expandPath in the put
command. File arguments should be treated literally β€” expanding
$var in filenames causes them to silently resolve to wrong paths
or empty strings.

Closes #105
@babarot babarot added the kind/bug A bug; unintended behavior label Mar 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Code Metrics Report

main (1e162c7) #111 (7379737) +/-
Coverage 50.0% 50.0% 0.0%
Code to Test Ratio 1:0.8 1:0.8 0.0
Test Execution Time 2s 2s 0s
Details
  |                     | main (1e162c7) | #111 (7379737) | +/-  |
  |---------------------|----------------|----------------|------|
  | Coverage            |          50.0% |          50.0% | 0.0% |
  |   Files             |             23 |             23 |    0 |
  |   Lines             |           1087 |           1087 |    0 |
  |   Covered           |            544 |            544 |    0 |
  | Code to Test Ratio  |          1:0.8 |          1:0.8 |  0.0 |
  |   Code              |           2713 |           2713 |    0 |
  |   Test              |           2321 |           2321 |    0 |
  | Test Execution Time |             2s |             2s |   0s |

Reported by octocov

@babarot babarot marked this pull request as ready for review March 20, 2026 09:01
@babarot babarot merged commit a985806 into main Mar 20, 2026
5 checks passed
@babarot babarot deleted the babarot/fix-dollar-sign-filename branch March 20, 2026 09:02
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 25, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [babarot/gomi](https://github.com/babarot/gomi) | patch | `v1.6.2` β†’ `v1.6.3` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>babarot/gomi (babarot/gomi)</summary>

### [`v1.6.3`](https://github.com/babarot/gomi/blob/HEAD/CHANGELOG.md#v163---2026-03-20)

[Compare Source](babarot/gomi@v1.6.2...v1.6.3)

##### Bug fixes

- Fix files with dollar signs in names being incorrectly expanded by [@&#8203;babarot](https://github.com/babarot) in [#&#8203;111](babarot/gomi#111)
- Fix cross-device link error in legacy storage by [@&#8203;babarot](https://github.com/babarot) in [#&#8203;112](babarot/gomi#112)

##### Improvements

- Fix empty files being excluded from restore list by [@&#8203;babarot](https://github.com/babarot) in [#&#8203;110](babarot/gomi#110)
- Fix gomi\_dir being ignored when strategy is auto by [@&#8203;babarot](https://github.com/babarot) in [#&#8203;113](babarot/gomi#113)
- Fix colors invisible on light terminal backgrounds by [@&#8203;babarot](https://github.com/babarot) in [#&#8203;114](babarot/gomi#114)

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

β™» **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

πŸ”• **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44Ny4xIiwidXBkYXRlZEluVmVyIjoiNDMuODcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6OnBhdGNoIl19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug A bug; unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with removing files with dollar character

1 participant