fix(gstack-paths): shell-quote output so eval is safe for paths with spaces#1580
Open
yannickspiess wants to merge 1 commit into
Open
fix(gstack-paths): shell-quote output so eval is safe for paths with spaces#1580yannickspiess wants to merge 1 commit into
yannickspiess wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GSTACK_HOME(and the other path roots) may contain spaces or shell metacharacters — for example an iCloud-synced directory underLibrary/Mobile Documents/.The current bare
echoemits unquoted output:When skills do
eval "$(gstack-paths)", bash/zsh split on the first space:GSTACK_STATE_ROOTgets set to/Users/me/Library/MobileDocuments/Obsidian/GStackas a commandResult:
command not foundandGSTACK_STATE_ROOTleft truncated/wrong.Fix
Add a POSIX-compatible
_shell_quotehelper that wraps each value in single quotes and properly escapes any embedded single quotes (the standard'\''\''form). Replace the threeecholines withprintf.Output now looks like:
Safe for paths containing: spaces,
$,;, backticks, double quotes, single quotes.Works in sh / bash / zsh / dash (no
printf %qwhich is bash/zsh-only).Testing
Verified with:
Library/Mobile Documents/iCloud~md~obsidian/...) — now worksNotes
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.