Repository navigation
fix(eval): hold the extglob parse gate for the whole eval unit (Refs #2876) - #2912
Merged
Merged
Conversation
Fail-first pins for #2876: with extglob on, an eval'd compound array assignment whose element carries an extglob pattern dies with a syntax error for all five operators, in callers, functions and command substitution, because the eval path restores the parse gate right after its reparse while compound-assignment element splitting reads the gate at execution time. GNU keeps one live value: builtins/shopt.def:640 (shopt_set_extglob writes extended_glob = extglob_flag), parse.y:3502 (reset_parser: extended_glob = extglob_flag), builtins/evalstring.c parse_and_execute parses and runs the string against that value. On master e8f1bb0 these pins read 1 passed / 5 failed; the single pass is the extglob-off parity control, which already agrees with GNU and must keep agreeing.
Two gate reads disagreed with GNU's single live extglob_flag
(builtins/shopt.def:640 shopt_set_extglob writes
extended_glob = extglob_flag; parse.y:3502 reset_parser propagates
it; builtins/evalstring.c parse_and_execute parses and runs the
string against it):
1. The eval-string shape scan (lexer::unclosed_comsub_eof_shape)
classified EVERY `(` inside a compound-assignment list as the
parse.y:7173-7179 token error, before the real parse ever ran.
read_token_word (parse.y:5466, PST_COMPASSIGN) consumes
word-internal openers into the element word — `$(`, `$((`, `<(`,
`>(`, a `${...}` body's parens, and a pattern operator's group
under the live gate — so an eval'd `arr=(x/!(a))`, `arr=($(cmd))`
or `arr=(${y:-(a)})` all died with the same syntax error. The
scan now models those constructs (new ExtglobGroup / Brace /
BraceParen frames, escaped-opener tracking) and keeps the token
error for a BARE `(` only; the eval caller passes the live option
state, the script driver passes the parse gate in force.
2. execute_eval_source_inner pinned PARSE_EXTENDED_GLOB only
around tokenize + parse and restored it before execution, while
compound-assignment element splitting reads the gate at
execution time (split_compound_assignment_words). The pin moves
to execute_eval_source — the parse_and_execute funnel shared by
eval and the mapfile -C callback — for the unit's whole
duration, and on exit re-pins to the live option state as it
then stands, so a shopt toggle executed by the eval'd text
persists exactly like GNU's single variable.
Also pins the word-internal construct family through eval (comsub,
arithmetic, procsub, ${} bodies, and the bare/escaped negatives).
caomengxuan666
marked this pull request as ready for review
November 6, 2026 15:04
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.
Fixes #2876 — UNVERIFIED-BY-CAPTAIN (lane delivery; captain verifies centrally)
What this fixes
With
extglobon, an eval'd compound array assignment whose element carries an extglob pattern was a syntax error for all five operators (! + * ? @), in scripts,-cstrings, functions, and$( ). This is the bash-completion_comp_expand_globshape (eval -- "$1=($2)") that broke shell startup with the distro bash-completion 2.14 loaded.GNU keeps ONE live extglob value for parse and execution alike:
builtins/shopt.def:640(shopt_set_extglob:extended_glob = extglob_flag),parse.y:3502(reset_parser:extended_glob = extglob_flag), andbuiltins/evalstring.cparse_and_executeparses and runs the string against that single value. Two rubash reads disagreed with it:The eval-string shape scan rejected the string before the real parse ran.
lexer::unclosed_comsub_eof_shape(the eval-family EOF diagnostics report the function-definition line instead of the invocation line (GNU: call site) #318/Regression gate gap: upstream_suite_slice_snapshots (errors.snap) red since before 12374592 — errors.tests stdout collapses 112→9 lines under stdin=null; snapshot suites absent from CI #333 diagnostic classifier in front ofexecute_eval) treated EVERY(inside a compound-assignment list as theparse.y:7173-7179token error. Butread_token_word(parse.y:5466, PST_COMPASSIGN) consumes word-internal openers into the element word —$(,$((,<(,>(, a${...}body's parens, and a pattern operator's group under the live gate — so the classifier also rejectedarr=($(cmd)),arr=($((1+2))),arr=(${y:-(a)})through eval (all verified against GNU 5.3.20). The scan now models those constructs (newExtglobGroup/Brace/BraceParenframes, backslash-escaped opener tracking) and keeps the token error for a BARE(only — including the escaped-opener negatives GNU keeps (x=(\$(a)),x=(a\!(b))stay errors). The eval caller passes the live option state (the same value the parse pin uses); the script-driver caller passes the parse gate in force for its unit.The parse gate was restored before execution.
Executor::execute_eval_source_innerpinnedPARSE_EXTENDED_GLOBto the live shopt state only around tokenize + parse and restored it before the eval'd text executed, while compound-assignment element splitting (split_compound_assignment_words,src/parser/assignment.rs) reads the gate at execution time. The pin now lives inExecutor::execute_eval_source— the parse_and_execute funnel shared byevaland the mapfile-Ccallback — for the whole unit, parse AND execution. On exit the gate is re-pinned to the live option state as it then stands, so ashopt -s/-u extglobexecuted by the eval'd text itself persists exactly as GNU's single variable does. Trap action strings use their own adjacent parse+execute site and are untouched.Pins (fail-first)
New stem
tests/issue2876_eval_extglob_array_regressions.rs, 7 tests: five operators through eval; the_comp_expand_globcall shape against real files; non-regression controls (direct assignment, eval×case from #1114, eval×bare glob word, nested eval, trap action); extglob-off parity controls (GNU rc=1, and enabling extglob inside the same string does not rescue it); shopt toggles inside eval persisting across evals; the word-internal construct family (comsub / arithmetic / procsub /${}bodies, plus bare and escaped negatives); function + command-substitution contexts.On master
e8f1bb04: 1 passed / 5 failed of the original 6 (the pass is the extglob-off parity control). Corpus check for #2900: sourcing the real bash-completion 2.14.0 file (3,349 lines, sha256859ddde4…) and calling_comp_expand_globreproduces the user's startup symptom on master (eval line 356 syntax error, empty result); GNU 5.3.20 and the fixed build both return the two non-.bak entries.本 PR 删除了什么
execute_eval_source_inner(the saved-gate snapshot and its immediate post-parse restore) — replaced by the whole-unit pin inexecute_eval_source.(in a compound list is a token error" rule — replaced by the word-internal-construct model; the bare-(error itself is kept.Net lines
Total +453 / −37 across 4 files (2 commits: pins
153459b5, fix2365ca40): new test stem +259;src/lexer/skip.rs+133 / −12 net;src/executor/trap_exec.rs+57 / −23 net;src/script_driver.rs+4 / −2 net.Lane validation (captain re-verifies centrally)
cargo check --locked --all-targets: clean.bash:argv0 prefix in diagnostics (the local binary path differs; content otherwise identical), issue1639 is a PTY Ctrl-C timing test whose failure count varies between runs (1→2) under load.