Skip to content

fix(procsub): accept { ...; } bodies on write-side >(...) substitution - #1315

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1223-procsub-brace-group
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1223-procsub-brace-group

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1223

Two divergences fixed:

  1. echo hello > >({ cat; }) died with >({ cat; }): ambiguous redirect. Materialization rewrites redirect.target to the carrier temp path but leaves the original word in target_metadata.raw; expand_redirect_operand_fields then fed that raw into expand_braces_with_optional_raw, where { cat; } reads as a brace group and the whole raw word came back as the "expanded" operand — whitespace → ambiguity. GNU never field-splits that operand: redir.c:298 redirection_expand → expand_word_internal's '<'/'>' cases (subst.c:11349-11378 extract_process_subst → subst.c:6362 process_substitute) return the substitution filename as the single field. expand_redirect_target now returns the materialized target verbatim whenever the raw operand is a >(/<( word.

  2. echo hello | tee >({ cat; }) >/dev/null left the external child a literal /dev/fd/63 word it could not open. dev_fd_table_operand returned None for FdWriteEndpoint::ProcessSubstitution; it now hands the child the carrier's real path (GNU redir.c: the fd is the write end of the procsub pipe).

Before:

$ rubash s.sh   # echo hello > >({ cat; }); echo done
s.sh: line 1: >({ cat; }): ambiguous redirect
done

After (== GNU 5.3.20):

hello
done

echo hello | tee >({ cat; }) >/dev/null now prints hello (was: tee: /dev/fd/63: No such file or directory).

Test plan

  • cargo test --test issue1223_procsub_brace_body — 3 tests green
  • cargo fmt --check clean

Generated with Devin

Two forms failed (rubash#1223):

1. `echo hello > >({ cat; })` died with `>({ cat; }): ambiguous
   redirect`. Materialization rewrites redirect.target to the carrier
   temp path but leaves the original `>({ cat; })` word in
   target_metadata.raw; expand_redirect_operand_fields then fed that raw
   into expand_braces_with_optional_raw, where `{ cat; }` reads as a
   brace group and the whole raw word returned as the "expanded" operand
   — whitespace -> ambiguity. GNU never field-splits that operand:
   redir.c:298 redirection_expand -> expand_word_internal's '<'/'>' cases
   (subst.c:11349-11378 extract_process_subst -> subst.c:6362
   process_substitute) return the substitution filename as the single
   field. expand_redirect_target now returns the materialized target
   verbatim whenever the raw operand is a `>(`/`<(` word.

2. `echo hello | tee >({ cat; }) >/dev/null` left the external child a
   literal /dev/fd/63 word it could not open. dev_fd_table_operand
   returned None for FdWriteEndpoint::ProcessSubstitution; it now hands
   the child the carrier's real path (the fd table entry already carries
   it), matching GNU's dup of the procsub pipe write end.

Verified vs WSL GNU Bash 5.3.20 (script-file probes):
  echo hello > >({ cat; }); echo done            -> hello / done
  echo hello > >( { cat; } ); echo done          -> hello / done
  echo hello | tee >({ cat; }) >/dev/null; done  -> hello / done

Generated with [Devin](https://devin.ai)
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger area:glob pathname expansion, shopt glob options, collation P2-medium 中:次要缺陷或边缘路径,排期修复 and removed bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复 area:glob pathname expansion, shopt glob options, collation labels Oct 23, 2026
@caomengxuan666
caomengxuan666 merged commit ac3961f into master Oct 23, 2026
12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1223-procsub-brace-group branch October 23, 2026 08:54
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.

[bug] Brace-group body { ...; } rejected on write-side >(...) (GNU runs it; read side works)

2 participants