Skip to content

fix(interpreter): expand array args as separate fields#201

Merged
chaliy merged 1 commit intomainfrom
claude/bash-color-array-pOryz
Feb 12, 2026
Merged

fix(interpreter): expand array args as separate fields#201
chaliy merged 1 commit intomainfrom
claude/bash-color-array-pOryz

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 12, 2026

Summary

  • Fix "${arr[@]}" expanding to a single space-joined argument instead of separate arguments for commands like printf
  • Set word.quoted=true for QuotedWord tokens in parser so "${arr[*]}" correctly joins elements into a single field while "${arr[@]}" produces separate fields
  • execute_dispatched_command now uses expand_word_to_fields instead of expand_word for argument expansion

Before: printf "%s\n" "${colors[@]}"Black Red Green Yellow Blue Magenta Cyan White (one line)
After: Each color printed on its own line (bash-compatible)

Test plan

  • Added 6 printf array expansion tests (positive: @ expansion, * expansion, multi-format, single element; negative: empty array)
  • Added 3 array expansion tests (@ as args, * quoted, @ unquoted)
  • All 582 spec tests pass (515 passed + 67 skipped)
  • 477/477 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
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: 87fe6eccc5

ℹ️ 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".

for word in &command.args {
let expanded = self.expand_word(word).await?;
// Use field expansion so "${arr[@]}" produces multiple args
let fields = self.expand_word_to_fields(word).await?;

Choose a reason for hiding this comment

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

P2 Badge Preserve empty arg for quoted unset ${arr[*]}

Switching argument expansion to expand_word_to_fields here changes "${arr[*]}" when arr is unset from one empty argument to zero arguments, because the helper returns an empty vector for missing arrays. In bash, quoted * expansion still yields one field (e.g. f(){ echo $#; }; unset arr; f "${arr[*]}" prints 1), so this is a compatibility regression for functions/builtins that depend on argument count.

Useful? React with 👍 / 👎.

@chaliy chaliy merged commit f5493c0 into main Feb 12, 2026
9 checks passed
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