Skip to content

Commit ac07116

Browse files
authored
fix(parser): reconstruct braces in process substitution token loop (#970)
## Summary - Fix group command `{ ... }` piped to another command producing no output inside process substitution `< <(...)` - Root cause: `LeftBrace` and `RightBrace` tokens were missing from the process substitution parser's token reconstruction loop, silently dropping them - Added 3 spec tests covering group+pipe, group+tac, group+sort inside process substitution ## What The process substitution parser reconstructs command strings from tokens to re-parse them. The match block handled `Pipe`, `Semicolon`, `And`, `Or`, etc. but was missing `LeftBrace` and `RightBrace`. These fell through to the catch-all `_` branch which silently dropped them, turning `{ echo a; echo b; } | cat` into `echo a; echo b; | cat`. ## Test plan - [x] 3 new spec tests: `process_subst_group_pipe`, `process_subst_group_pipe_tac`, `process_subst_group_pipe_sort` - [x] All existing procsub tests still pass - [x] Manual verification: `cat < <({ echo "line1"; echo "line2"; } | cat)` now outputs correctly - [x] `cargo fmt --check` clean - [x] `cargo clippy` clean - [x] Full test suite green Closes #947
1 parent b7b2281 commit ac07116

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

crates/bashkit/src/parser/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,17 @@ impl<'a> Parser<'a> {
24482448
cmd_str.push_str(&format!(" {}> ", fd));
24492449
self.advance();
24502450
}
2451+
Some(tokens::Token::LeftBrace) => {
2452+
if !cmd_str.is_empty() {
2453+
cmd_str.push(' ');
2454+
}
2455+
cmd_str.push('{');
2456+
self.advance();
2457+
}
2458+
Some(tokens::Token::RightBrace) => {
2459+
cmd_str.push_str(" }");
2460+
self.advance();
2461+
}
24512462
Some(tokens::Token::Newline) => {
24522463
cmd_str.push('\n');
24532464
self.advance();

crates/bashkit/tests/spec_cases/bash/procsub.test.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,32 @@ a
101101
b
102102
c
103103
### end
104+
105+
### process_subst_group_pipe
106+
### bash_diff: requires /dev/fd/
107+
# { ... } | cmd inside < <(...) should produce output
108+
while IFS= read -r line; do echo "$line"; done < <({ echo "a"; echo "b"; } | cat)
109+
### expect
110+
a
111+
b
112+
### end
113+
114+
### process_subst_group_pipe_tac
115+
### bash_diff: requires /dev/fd/
116+
# { ... } | tac inside < <(...)
117+
while IFS= read -r line; do echo "$line"; done < <({ echo "1"; echo "2"; echo "3"; } | tac)
118+
### expect
119+
3
120+
2
121+
1
122+
### end
123+
124+
### process_subst_group_pipe_sort
125+
### bash_diff: requires /dev/fd/
126+
# { ... } | sort inside < <(...)
127+
while IFS= read -r line; do echo "$line"; done < <({ echo "c"; echo "a"; echo "b"; } | sort)
128+
### expect
129+
a
130+
b
131+
c
132+
### end

0 commit comments

Comments
 (0)