Skip to content

fix(interpreter): apply brace/glob expansion in for-loop word list#204

Open
chaliy wants to merge 2 commits intomainfrom
claude/bash-color-array-pOryz
Open

fix(interpreter): apply brace/glob expansion in for-loop word list#204
chaliy wants to merge 2 commits intomainfrom
claude/bash-color-array-pOryz

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 12, 2026

Summary

  • Fix for i in {0..5} iterating once with literal {0..5} instead of expanding to 0 1 2 3 4 5
  • execute_for now applies expand_braces and expand_glob to each word in the for-loop list, matching execute_dispatched_command behavior
  • Quoted words ("${arr[@]}") still skip brace/glob expansion as expected

Before: for i in {0..5}; do echo $i; done0 1 2 3 4 5 (one iteration, literal string)
After: Each number printed on its own line (6 iterations, bash-compatible)

Test plan

  • Added 3 brace expansion for-loop tests (numeric range, comma, printf with range)
  • All 585 spec tests pass (518 passed + 67 skipped)
  • 480/480 bash comparison tests match real bash (100%)
  • Full test suite passes (cargo test --all-features)
  • cargo fmt --check clean
  • cargo clippy --all-targets --all-features -- -D warnings clean

"${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
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +2702 to +2703
if word.quoted && index == "*" {
return Ok(vec![values.join(" ")]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants