fix(interpreter): split command substitution output on IFS in list context#374
Merged
fix(interpreter): split command substitution output on IFS in list context#374
Conversation
5c28718 to
b378a79
Compare
…ntext Unquoted $() results in for-loop word lists (and other list contexts) were treated as a single token. Now expand_word_to_fields performs IFS-based field splitting when the word is unquoted and contains a CommandSubstitution part, matching POSIX/bash semantics. Added spec tests: for-loop with find, space-separated words, newlines. Closes #347
Replace filesystem-dependent find command with printf to avoid VFS vs real filesystem mismatch in CI comparison tests. The test still validates word-splitting of command substitution output in for-loop list context.
b378a79 to
01ffa67
Compare
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.
Summary
$()command substitution in list contexts (e.g.,for x in $(cmd))Details
The root cause was in
expand_word_to_fields()incrates/bashkit/src/interpreter/mod.rs. For words that weren't array expansions, it calledexpand_word()which returns a single concatenated string, then wrapped it in a single-element vec. There was no IFS-based field splitting step for unquoted command substitutions.The fix checks if the word is unquoted and contains a
CommandSubstitutionpart. If so, the expanded result is split on IFS characters (defaulting to space/tab/newline), with consecutive whitespace collapsed and empty results elided. This matches POSIX shell semantics and real bash behavior.Test plan
command-subst.test.sh(for-loop splitting, space splitting, newline splitting)cargo fmt --checkcleancargo clippy --all-targets --all-features -- -D warningscleanCloses #347