Repository navigation
WIP: expansion batch — #1993 #1981 #1960 #1949 #1930 #1931 #1932 #1933 #1657 #1982 - #2008
Merged
caomengxuan666 merged 12 commits intoOct 29, 2026
Conversation
… strerror The word-level cat arm printed a blanket quoted `'<path>': No such file or directory` for every read failure, crushing EISDIR (directory operand), ENOTDIR (traversal through a regular file) and ELOOP (symlink loop) into a fake ENOENT. GNU has no such arm: subst.c:7143 command_substitute() runs the real cat through parse_and_execute, and cat's diagnostic is `cat: PATH: <strerror>`. The arm now prints the io::Error it already receives via crate::posix_errors::message — the same helper the external cat builtin formats with — so the reason text always comes from the failure that produced it. Pins: tests/issue1949_cat_substitution_error_regressions.rs (directory / not-a-directory / symlink-loop / plain ENOENT stays unquoted), all measured against GNU bash 5.3.20.
subst.c:9777 parameter_brace_expand() splits the braced body at
the first operator: in `${v=x:=y}` the parameter is `v`, the
operator is `=`, and the word is the literal `x:=y`. The handler
claimed the `:=` inside the word first, derived the non-name
target `v=x`, rejected it, and returned without ever trying the
`=` arm — so nothing was bound.
The `:=` claim split now passes through the same
assignment-target filter as the `=` arm, and
parameter_assignment_target considers both operator candidates,
accepting only the first whose base is a shell name or an array
element. `${v:=x:=y}` still claims via `:=`; `${a:-x=y:=z}` is
still not claimed at all.
Pins: tests/issue1960_assign_word_operator_regressions.rs,
measured against GNU bash 5.3.20.
…cat operand shapes The heredoc command-substitution plan executed `cat` commands without looking at their operands: `$(cat file <<EOF)` substituted the heredoc body and never read the file, and a three-stage pipeline was silently truncated to the two stages the plan models. GNU subst.c:7143 command_substitute() runs parse_and_execute — there is no operand-blind fast path. Per the repo's no-whack-a-mole rule the admission is a whitelist over operand SHAPE: the plan runs only when every cat it models has no operands or one bare `-` (the heredoc dash), and the decomposed command has at most the two pipeline stages the plan produces. Any other composition — a file operand, an option, a dash plus a file, a third stage — declines to the real executor. Pins: tests/issue1981_heredoc_comsub_operand_regressions.rs, measured against GNU bash 5.3.20.
… heredoc in comsub `x=$(cat <<EOF)` (paren on the header line) leaves the heredoc unterminated by its delimiter: GNU warns `warning: command substitution: 1 unterminated here-document` and still substitutes the body; master was silent. Ownership is the reader/feeder layer, not expansion: the feeder relocates the closing paren past the heredoc delimiter — the same reprint GNU performs in print_cmd.c:164 print_comsub() — which erases the header-close evidence before the heredoc plan sees the source, and the plan's surviving warning site was additionally gated on typed-input warnings, which script files never set. The relocation now tracks which `$(` a closing paren belongs to and marks the extracted stream when that paren sat on the header line; the plan warns on the mark (or on source text that still shows the shape when no relocation happened), unconditionally — a declined plan is memoized, so the warning still fires exactly once. The paren-on-delimiter-line shape keeps its separate delimited-by-EOF warning, and the paren-on-its-own-line shape stays silent. Pins: tests/issue1982_heredoc_header_close_warning_regressions.rs, measured against GNU bash 5.3.20.
… before scanning
`echo hi > '$NOPE'` under `set -u` was rejected with
`NOPE: unbound variable` although the target is one literal word.
GNU redir.c:298 redirection_expand() expands the target as a word
(parse.y:5305 read_token_word): single-quoted text is literal, and
the unbound report exists only for parameters actually expanded.
The gate fed the RAW target text to a scanner whose contract is
carrier-encoded words, so it could not see quotes, escapes or
$'...'. The gate now masks the raw target first: single-quoted
spans and $'...' collapse away, backslash pairs are neutralized
exactly where the shell neutralizes them (inside double quotes
only before $ ` " \), and $(...)/${...}/backtick units are copied
verbatim so parameters that DO expand inside a double-quoted
target are still reported — exactly once, by the gate, as GNU's
fatal report requires.
Pins: tests/issue1930_nounset_redirect_quote_regressions.rs,
measured against GNU bash 5.3.20.
…eral filenames A double-quoted process-substitution-shaped redirect target was materialized as a real substitution: the body ran (side effects included) and its parameters were diagnosed twice — once by the nounset gate over the target, once by the body's own expansion. GNU redir.c:298 redirection_expand() expands the target as a word, and parse.y:5305 read_token_word records a process-substitution span only for an UNQUOTED <( / >(: the quoted target is the literal filename `<(echo hi)`, whose open simply fails. The trace was materialization sites pattern-matching the quote-stripped target VALUE. Simple-command materialization (the external-command redirect setup and the compound OUTPUT path, whose fall-through has a real error channel) now admits a span only when the redirect's recorded process-substitution metadata covers the whole target (redirect_target_span_is_recorded); a quoted shape falls to the ordinary literal-file open, whose ENOENT diagnostic is the single report. The gate's open probes use the same admission instead of a starts_with exemption. Compound INPUT binding is deliberately left matching by value, with the reason recorded at the site: that layer has no literal-target error channel yet, and declining the spawn there would leave the compound reading ambient stdin (a hang) instead of GNU's error — a worse divergence than the current wrong answer. Pins: tests/issue1931_quoted_procsub_redirect_regressions.rs, measured against GNU bash 5.3.20.
…sub spans Conditional operands never materialized their process substitutions: `[[ <(echo hi) == /dev/fd/* ]]` was false and `[[ -n <(echo hi) ]]` reduced the span to literal text, because expand_conditional_word had no materialization step while the recorded-span table was only consulted for operator positions. GNU expands the operand as a word (subst.c cond_expand_word), in which <(...) becomes the substitution's /dev/fd path. expand_conditional_word now splices each span the parse recorded for THIS word into a live fd word before expanding: input spans run the child and serve its output under the conditional wrapper's existing fd lifecycle; output spans reserve the fd word and register the drain with the same wrapper. Restricting to recorded spans keeps a quoted "<(echo hi)" operand literal, matching GNU. Pins: tests/issue1932_conditional_procsub_spans_regressions.rs, measured against GNU bash 5.3.20.
…ial procsub span `[[ -n <(echo hi)x ]]` was a syntax error: the compound-word collector stopped after a leading process-substitution span and then demanded an operator or terminator. GNU parse.y:5305 read_token_word assembles ONE word from adjacent fragments — a span is a word fragment, and unspaced text after its closing paren (a literal run, a $-fragment, a second span) belongs to the same word. The collector now glues every adjacent fragment the lexer hands it without intervening whitespace, for both span directions; the case-command subject, the collector's other caller, reads such words the same way. Whitespace-separated words keep their existing parse (a syntax error inside [[ ]] without an operator). Pins: tests/issue1933_conditional_procsub_suffix_regressions.rs, measured against GNU bash 5.3.20.
With a set-empty IFS, Posix interp 888 dispatches unquoted $* to
the dollar_at word list (subst.c string_list_pos_params): one
word per parameter, and an entirely-empty parameter contributes
NO word. Four arms broke that model:
- the command-word arms for $* and ${*} returned the positional
window verbatim, so an empty parameter became an empty word;
- the for-list path had no arm at all and fell to the scalar path,
joining the parameters with the empty separator into ONE word;
- the operator-word arm ${var-$*} returned the window verbatim
too, although GNU's W_SPLITSPACE pass over the space-joined
escaped elements drops empties at the join spaces;
- the double-quoted ${param+word} alternate re-lexed only $@ as a
quoted word, so "${1+ $* }" field-split $* and lost the join —
quoted $* is ONE field, the IFS[0] join (subst.c
string_list_dollar_star), which now takes the same re-lex.
Non-empty-IFS forms are unchanged (an empty parameter survives
field splitting there, as GNU measures).
Pins: tests/issue1993_dollar_star_regressions.rs, measured
against GNU bash 5.3.20.
…on, no code change) The report claimed ~name for a system user missing from the shell's own list expands to `/`. There is no shell-side user list on unix: passwd_home_for_user is libc::getpwnam_r verbatim — the same lookup GNU tilde.c performs for ~name — a miss keeps the word verbatim, and a hit returns the passwd entry's home, including an entry whose pw_dir really is `/`. The reported shape comes from a platform libc passwd database (Android bionic's synthetic AID entries record `/` as those users' home); both shells print `/` there because the database says so. Measured locally against GNU bash 5.3.20: ~daemon -> /usr/sbin, ~bin -> /bin, ~root -> /root on both shells, ~nosuchuser stays literal on both. These pins lock the contract (resolve through the database, stay literal on a miss) so a future hardcoded table or `/` fallback cannot pass silently.
…anged) Two pins carried wrong expectations, caught on a serial re-run: - issue1960 noclaim: `declare -p a 2>&1 | head -1` routes the not-found message into stdout, so the asserted stdout could never match; the pin now checks unset-ness with [[ -v a ]], which GNU and rubash answer identically (unbound). - issue1982 delimiter-line: the expected warning text was written from memory. GNU 5.3.20 and rubash both emit `line 3: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')` — the pin now asserts the measured string. No product code changes; both shapes verified byte-identical between GNU bash 5.3.20 and the fixed binary before re-pinning.
caomengxuan666
marked this pull request as ready for review
October 29, 2026 02:14
caomengxuan666
deleted the
fix/expansion-batch-1993-1981-1960-1949-1930-1931-1932-1933-1657
branch
October 30, 2026 01:41
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.
WIP draft — expansion-face batch, one commit per issue, GNU 5.3.20 oracle expectations. Per-issue root cause, change and gate ledger: cluster REPORT in the work area (fix-expansion-batch/REPORT.md); each commit message carries the owning GNU C anchor.
Fixes #1993
Fixes #1981
Fixes #1960
Fixes #1949
Fixes #1930
Fixes #1931
Fixes #1932
Fixes #1933
Fixes #1657
Fixes #1982
#1657 adjudication (no code change in this PR)
#1657's premise does not reproduce as a code defect. There is no shell-side user list on unix: rubash's tilde owner resolves
~namethroughlibc::getpwnam_rverbatim — the same lookup GNU tilde.c performs — a miss keeps the word literal, a hit returns the passwd entry's home (including an entry whose pw_dir really is/). Measured against GNU bash 5.3.20 on this machine:~daemon->/usr/sbin,~bin->/bin,~root->/rooton BOTH shells;~nosuchuser123stays literal on both. The reported/expansions are attributable to the platform libc passwd database (Android bionic's synthetic AID entries record/as those users' home directories) — both shells print/there because the database says so. This PR carries only a contract regression pin (tests/issue1657_tilde_passwd_contract_regressions.rs) so a future hardcoded table or/fallback cannot pass silently. TheFixes #1657line above is kept for the main session to adjudicate (strip it if the issue should stay open as a platform note).#1931 scope note
The reported double diagnostic traced to a wider family: quoted
"<(...)"/">(...)"redirect targets were materialized as real substitutions (bodies ran with side effects). Simple-command materialization and the compound OUTPUT path now admit only recorded spans. Compound INPUT binding still matches by value — deliberately: that layer has no literal-target error channel yet, and declining the spawn there would hang the compound on ambient stdin instead of reporting GNU's error. Recorded as a known adjacent divergence in the cluster report and at the code site.