fix(interpreter): apply brace/glob expansion in for-loop word list#204
fix(interpreter): apply brace/glob expansion in for-loop word list#204
Conversation
"${arr[@]}" was joining all elements with spaces into a single argument
instead of producing separate arguments. This broke printf format
repetition (e.g., `printf "%s\n" "${colors[@]}"` printed all on one line).
Root cause: execute_dispatched_command used expand_word which joins array
elements. Now uses expand_word_to_fields which preserves separate fields.
Also:
- Set word.quoted=true for QuotedWord tokens in parser (command args and
for-loop words) so "${arr[*]}" correctly joins into single field
- expand_word_to_fields distinguishes @ (separate fields) from * (joined
when quoted)
https://claude.ai/code/session_01AMR6sQEAyh5DXc13jvb9oK
for-loop's execute_for only called expand_word_to_fields on its word
list without applying brace or glob expansion. This meant `for i in
{0..5}` iterated once with literal "{0..5}" instead of 6 times.
Now applies expand_braces + expand_glob to each field (skipped for
quoted words), matching execute_dispatched_command behavior.
https://claude.ai/code/session_01AMR6sQEAyh5DXc13jvb9oK
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e10190242d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if word.quoted && index == "*" { | ||
| return Ok(vec![values.join(" ")]); |
There was a problem hiding this comment.
Handle unset "${arr[*]}" as one empty field
expand_word_to_fields only applies the quoted-* join logic when the array exists; when it is unset, it falls through and returns Vec::new(). After this commit switched command argument expansion to this helper, "${arr[*]}" now disappears instead of yielding one empty argument (bash gives argc=1), which changes behavior for scripts/functions that rely on quoted star expansion with unset arrays.
Useful? React with 👍 / 👎.
Summary
for i in {0..5}iterating once with literal{0..5}instead of expanding to0 1 2 3 4 5execute_fornow appliesexpand_bracesandexpand_globto each word in the for-loop list, matchingexecute_dispatched_commandbehavior"${arr[@]}") still skip brace/glob expansion as expectedBefore:
for i in {0..5}; do echo $i; done→0 1 2 3 4 5(one iteration, literal string)After: Each number printed on its own line (6 iterations, bash-compatible)
Test plan
cargo test --all-features)cargo fmt --checkcleancargo clippy --all-targets --all-features -- -D warningsclean