feat(shell): $VAR in mixed words and double quotes (segment model)#49
Merged
Conversation
WHAT: $VAR/${VAR} expansion is no longer whole-word-only. parse.rs gains a Seg{Lit|Var} and Arg::Var now carries Vec<Seg>, so a word can interleave literals and variables ($HOME/config, pre$X.log) — and a $VAR inside double quotes now expands too. read_var_name drops the whole-word restriction; a word that is BOTH a glob and variable-bearing is refused (deferred).
WHY: paths like $HOME/config and quoted "$HOME/x" are the common real forms; whole-word-only was too thin. Security is unchanged: the secret-free allowlist is still a NAME-only check in invoke before any spawn (each Seg::Var name must be allowlisted — so even a mixed word like pre$SECRET is denied), and value substitution stays in the real spawner (no re-split/re-glob of the value → no re-injection). No new seam needed — same mockability as before (allowlist mocked in invoke; value read integration-tested).
TEST: parser (mixed/quoted segments; ${X} braces; glob+var refused; invalid/bare/$( refused; escaped \$ literal) + mocked (allowlisted var reaches spawner as segments; non-allowlisted denied incl. inside a mixed word; var-as-program denied) + real (echo $HOME/sub and "prefix-$HOME" expand to env values). just check green; all prior tests pass. Partial #46 — redirect-target $VAR and glob+var remain (smaller follow-ups).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HMGPEApE4XfwgMhgFbRn6c
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.
Part of #46. Makes
$VAR/${VAR}expansion work in mixed words ($HOME/config,pre$X.log) and inside double quotes ("$HOME/x"), not just whole-word.What
parse.rs— aSeg { Lit | Var }type;Arg::Varnow carriesVec<Seg>, so a word interleaves literal runs and variable references.read_var_namedrops the whole-word restriction; double-quote$VARexpands. A word that is both a glob and variable-bearing ($DIR/*.rs) is refused (deferred).shell_tool.rs—invokeallowlists everySeg::Varname before any spawn;expand_stage_argvconcatenates segments (literals as-is, allowlisted vars from the env) into one literal.Security (unchanged shape)
The secret-free allowlist is still a name-only check in
invokebefore any spawn — so even a mixed word likepre$AWS_SECRET_KEYis denied. Value substitution stays in the real spawner; single-literal, no re-split / no re-glob of the value (no re-injection). No new seam — same mockability (allowlist mocked ininvoke; value read integration-tested).Testing
${X}braces; glob+var refused; invalid/bare-$/$(refused; escaped\$literal.echo $HOME/subandecho "prefix-$HOME"expand to the env value.Remaining on #46 (smaller follow-ups, left open)
$VARin redirect targets (> $TMPDIR/out) — needs the redirect path to become segments + an env seam to keep the resolved-path leash mockable.$DIR/*.rs).Test plan
just checkgreen (fmt + clippy all-features & no-default-features + workspace tests).🤖 Generated with Claude Code