Quote activation exports and paths for space-containing roots#545
Conversation
| { | ||
| name: "ActivationWorksWhenPathContainsSpaces", | ||
| script: ` | ||
| mkdir -p "env with spaces" |
There was a problem hiding this comment.
I found that this example passes before the fix. Can we use a more complex path like your unit test "/tmp/Application Support/hermit env"?
There was a problem hiding this comment.
Good catch! Updated in 023c4ee and codex's explanation on why the original test shape didn't actually reveal the issue.
Details
export accepts both of these argument forms:
NAME=value(assign + export)NAME(export an existing variable, or create empty one)
So when unquoted output is:
export HERMIT_ENV=/tmp/env with spacesthe shell parses it as 3 arguments:
HERMIT_ENV=/tmp/envwithspaces
with and spaces match valid shell variable-name syntax ([A-Za-z_][A-Za-z0-9_]*), so export accepts them. No syntax error.
That means:
HERMIT_ENVgets the wrong truncated value (/tmp/env)withandspacesare just exported as variables- command still exits successfully
But with:
export HERMIT_ENV=/tmp/Application Support/hermit envone token becomes Support/hermit, which is not a valid variable name (contains /), so export errors. That’s why the Application Support/hermit env shape reliably exposes the bug.
| set -gx HERMIT_ENV_OPS $("$HERMIT_ENV/bin/hermit" env --ops) | ||
| set -gx ACTIVE_HERMIT "$HERMIT_ENV" | ||
| set -gx HERMIT_ENV_OPS "$("$HERMIT_ENV/bin/hermit" env --ops)" | ||
| set -gx HERMIT_BIN_CHANGE $(date -r "$HERMIT_ENV/bin" +"%s") |
There was a problem hiding this comment.
For consistency can we add "" to:
| set -gx HERMIT_BIN_CHANGE $(date -r "$HERMIT_ENV/bin" +"%s") | |
| set -gx HERMIT_BIN_CHANGE "$(date -r "$HERMIT_ENV/bin" +"%s")" |
and
set CURRENT "$(date -r "$HERMIT_ENV/bin" +"%s")"
too?
023c4ee to
fe806cf
Compare
Note
Disclaimer: I'm not a go dev but hit this bug today and figured I'd throw up a PR with the assistance of AI. Feel free to mock and/or shame me 😂
Summary
evalis safe when environment roots contain spacesHow This Was Discovered
This surfaced while running Hermit from a CodexMonitor-managed git worktree. CodexMonitor stores worktrees under:
~/Library/Application Support/com.dimillian.codexmonitor/worktrees/...Because
Application Supportcontains a space,source bin/activate-hermitfailed whenhermit activateemitted unquotedexportvalues. Shellevalsplit those values, causing activation errors in zsh/bash.Testing
go test ./...go test -tags=integration ./integration -run 'TestIntegration/ActivationWorksWhenPathContainsSpaces' -count=1This response was drafted with AI assistance.