Skip to content

fix(gstack-paths): shell-quote output so eval is safe for paths with spaces#1580

Open
yannickspiess wants to merge 1 commit into
garrytan:mainfrom
yannickspiess:fix/gstack-paths-shell-quote-spaces
Open

fix(gstack-paths): shell-quote output so eval is safe for paths with spaces#1580
yannickspiess wants to merge 1 commit into
garrytan:mainfrom
yannickspiess:fix/gstack-paths-shell-quote-spaces

Conversation

@yannickspiess
Copy link
Copy Markdown

Problem

GSTACK_HOME (and the other path roots) may contain spaces or shell metacharacters — for example an iCloud-synced directory under Library/Mobile Documents/.

The current bare echo emits unquoted output:

GSTACK_STATE_ROOT=/Users/me/Library/Mobile Documents/Obsidian/GStack

When skills do eval "$(gstack-paths)", bash/zsh split on the first space:

  • GSTACK_STATE_ROOT gets set to /Users/me/Library/Mobile
  • The shell then tries to execute Documents/Obsidian/GStack as a command

Result: command not found and GSTACK_STATE_ROOT left truncated/wrong.

Fix

Add a POSIX-compatible _shell_quote helper that wraps each value in single quotes and properly escapes any embedded single quotes (the standard '\''\'' form). Replace the three echo lines with printf.

Output now looks like:

GSTACK_STATE_ROOT='/Users/me/Library/Mobile Documents/Obsidian/GStack'
PLAN_ROOT='/Users/me/.claude/plans'
TMP_ROOT='/var/folders/...'

Safe for paths containing: spaces, $, ;, backticks, double quotes, single quotes.

Works in sh / bash / zsh / dash (no printf %q which is bash/zsh-only).

Testing

Verified with:

  • Normal path (no spaces) — behaviour unchanged
  • Path with spaces — now works
  • Actual iCloud vault path (Library/Mobile Documents/iCloud~md~obsidian/...) — now works

Notes

The existing comment said "output values are not sanitized" — that warning is now removed since the output is sanitized. No other call sites need changing; the output contract (eval "$(gstack-paths)") is preserved.

…spaces

GSTACK_HOME (and the other path roots) may contain spaces or shell
metacharacters — for example an iCloud-synced directory under
`Library/Mobile Documents/`.  The previous bare echo emitted:

  GSTACK_STATE_ROOT=/path/with spaces

which eval split at the first space, leaving GSTACK_STATE_ROOT truncated
and attempting to execute the remainder as a command.

Fix: add a POSIX-compatible _shell_quote helper that wraps values in
single quotes and escapes any embedded single quotes. Works in
sh / bash / zsh / dash.

Tested with:
- normal path (no spaces)    — unchanged behaviour
- path with spaces           — now works
- path with single quote     — now works
- actual iCloud vault path   — now works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant