From 80652f299c2e69c2440582d1012e2924401f7c84 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Thu, 2 Apr 2026 04:56:44 +0000 Subject: [PATCH] fix(parser): reconstruct braces in process substitution token loop The process substitution parser reconstructs command strings from tokens but was missing handlers for LeftBrace and RightBrace. These tokens fell through to the catch-all branch which silently dropped them, causing `{ echo a; echo b; } | cat` inside `<(...)` to lose its group structure. Closes #947 --- crates/bashkit/src/parser/mod.rs | 11 +++++++ .../tests/spec_cases/bash/procsub.test.sh | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/crates/bashkit/src/parser/mod.rs b/crates/bashkit/src/parser/mod.rs index 67f0da9b..d26e61a8 100644 --- a/crates/bashkit/src/parser/mod.rs +++ b/crates/bashkit/src/parser/mod.rs @@ -2448,6 +2448,17 @@ impl<'a> Parser<'a> { cmd_str.push_str(&format!(" {}> ", fd)); self.advance(); } + Some(tokens::Token::LeftBrace) => { + if !cmd_str.is_empty() { + cmd_str.push(' '); + } + cmd_str.push('{'); + self.advance(); + } + Some(tokens::Token::RightBrace) => { + cmd_str.push_str(" }"); + self.advance(); + } Some(tokens::Token::Newline) => { cmd_str.push('\n'); self.advance(); diff --git a/crates/bashkit/tests/spec_cases/bash/procsub.test.sh b/crates/bashkit/tests/spec_cases/bash/procsub.test.sh index d2c68b76..b218d7b3 100644 --- a/crates/bashkit/tests/spec_cases/bash/procsub.test.sh +++ b/crates/bashkit/tests/spec_cases/bash/procsub.test.sh @@ -101,3 +101,32 @@ a b c ### end + +### process_subst_group_pipe +### bash_diff: requires /dev/fd/ +# { ... } | cmd inside < <(...) should produce output +while IFS= read -r line; do echo "$line"; done < <({ echo "a"; echo "b"; } | cat) +### expect +a +b +### end + +### process_subst_group_pipe_tac +### bash_diff: requires /dev/fd/ +# { ... } | tac inside < <(...) +while IFS= read -r line; do echo "$line"; done < <({ echo "1"; echo "2"; echo "3"; } | tac) +### expect +3 +2 +1 +### end + +### process_subst_group_pipe_sort +### bash_diff: requires /dev/fd/ +# { ... } | sort inside < <(...) +while IFS= read -r line; do echo "$line"; done < <({ echo "c"; echo "a"; echo "b"; } | sort) +### expect +a +b +c +### end