Repository navigation
fix(word): expand globs for every simple command via typed words - #244
Merged
hyperpolymath merged 2 commits intoNov 18, 2026
Merged
Conversation
Glob expansion lived only in `external::expand_glob_args`, which only `execute_external_with_redirects` called. `wc -c *.txt` passed `*.txt` to wc, pipeline stages and `echo` never expanded, and quoted metacharacters reached programs with the tokenizer's escape backslash (`echo '*.txt'` printed `\*.txt`). The tokenizer now also builds a typed `word::Word` that records the quoting of each piece (unquoted, single, double, backslash). `word::expand_words` runs tilde, parameter, command, arithmetic and process substitution, then brace expansion, glob expansion and quote removal on it. External commands (with or without redirections and in the background), every pipeline stage, `echo`, function calls, command substitution and process substitution use it; `Command::External`, `Command::Pipeline` and `Command::Echo` carry `Vec<Word>` arguments. Rules kept from `expand_glob_args`: no match or an invalid pattern keeps the word; a `GlobLimitExceeded` fails the command (exit 1) without running it. Builtin operands, redirection targets, assignments, `case` and `test` still use the old string encoding (documented in POSIX_COMPLIANCE.adoc). Also: `$( ... )` is read to its matching `)`, so `$((1+(2*3)))` is one substitution, and `$(echo ...)` is supported. Tests: unit tests in word.rs, a Display/tokenize round-trip property test, and end-to-end tests through the vsh binary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDfX8Xoq6vedAKdWBif
SonarCloud rust:S3776 flagged the cognitive complexity of Display::fmt on PR #244. The per-quoting literal case is now fmt_literal; output is unchanged (round-trip property test and Display unit test pass). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDfX8Xoq6vedAKdWBif
|
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.



Stacked on #242 (
claude/gifted-planck-mha9c9), which addsglob::expand_glob_with_limitsandGlobLimitExceeded. Once #242 merges, retarget this PR tomain.Problem (measured on the debug binary, directory with
a.txt b.txt c.log)wc -c *.txtwc: '*.txt': No such file or directory0 a.txt/0 b.txt/0 totalls *.txt | wc -lls: cannot access '*.txt'2echo *.txt*.txta.txt b.txtecho '*.txt'\*.txt*.txtecho a{1,2}/echo $((2+3))a{1,2}/$((2+3))a1 a2/5Cause: argument globbing lived only in
external::expand_glob_args, which onlyexecute_external_with_redirectscalled. There was also a second bug: quoted metacharacters were marked with a backslash in the token string, and nothing ever removed it.Change: typed word IR
src/word.rs. AWordrecords the quoting of each piece (unquoted,'…',"…",\x).expand_wordsruns, in order: tilde, parameter, command and arithmetic expansion, process substitution, then brace expansion, glob expansion and quote removal.Wordnext to the old string form.Command::External,Command::PipelineandCommand::Echonow carryVec<Word>.echo, function-call arguments, and theExternalbranch of command substitution and process substitution.GlobLimitExceededfails the command without running it (vsh: prog: …, exit 1).external::expand_glob_argsis removed. Its rules and tests moved toword.rs.$(…)is now read to its matching), so$((1+(2*3)))is a single substitution.$(echo …)is supported.Behaviour changes
execute()asErr. In-cmode that printedError:plus a backtrace. Now the command exits with status 1 and does not run.$Xwhose value contains glob characters is now globbed, as POSIX requires. A quoted"$X"is not.Not migrated in this PR
These still read the old string encoding, so their behaviour is unchanged and still differs from bash:
touch '*q'creates\*q;ls *.txtas a builtin does not glob)X='*.txt'stores\*.txt)casepatterns,test/[[ ]]arguments,forword listsField splitting is still not done. All of this is documented in
docs/POSIX_COMPLIANCE.adoc, Milestones 5 and 6.Tests
tests/word_expansion_e2e_tests.rsruns thevshbinary. It covers:echo'…',"…"and\*, which stay literal with no backslash'*'x.*)word.rs: the limit error, an invalid pattern, a literal backslash inside a pattern, quoted vs unquoted parameters, and refused process substitution.parser.rs:Displaythentokenizegives back the sameWord(256 cases). The domain excludes backticks inside double quotes, because the tokenizer has no ``` escape.cargo fmt --check,cargo clippy --all-targets -- -D warnings: clean.cargo test: 887 passed, 0 failed, 14 ignored (the same ignored set as before: stress tests, the model oracle and 2 in the lib).Generated by Claude Code