Repository navigation
lexer: snapshot the extglob gate at read-unit entry (Refs #3205) - #3223
Merged
Merged
Conversation
Same-line shopt -s extglob must not leak into the same read unit's lexing (GNU parse.y read_command cadence; read_token_word consults the read-time extended_glob at parse.y:5466). Defect cells x4 (&& segment glob-expanded, rc=0 vs GNU rc=2) and x1b (command- position !( read as pattern head, rc=2 vs GNU negated subshell rc=0) plus five extended cells of the same invariant (previous- unit gate already on, multi-line if-body unit, earlier && segment, @( under &&, pipeline stage) fail on master 9cbe029; the four control cells (no-shopt !(, previous-line shopt, -c newline form, ';' argument position) pass. Expectations byte-verified against GNU bash 5.3.20. Refs #3205
A read unit is fully read before any of it executes (GNU parse.y read-time extended_glob), so a same-line 'shopt -s extglob' must not change how the rest of the unit is lexed. The gather feeder flipped the global parse gate per line while simulating the unit, and the fresh re-lex of a flipping group then started from the group-end state, leaking the unit's own shopt into its trailing segments. - lexer: park extglob flips in a deferred slot (mirroring the deferred posix-mode model) and land them only at unit boundaries. - script_driver / source driver: pin the gate to the group-entry snapshot around the fresh re-lex of a gathered group and restore it afterwards. - parser: the parse-time extglob error marker now arms only when the enabling shopt token itself was lexed with the gate off, so a unit that starts with the gate already on is not misdiagnosed. Refs #3205
caomengxuan666
marked this pull request as ready for review
November 10, 2026 03:56
This was referenced Nov 10, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 10, 2026
executor: stop swallowing expanded '#' command words as comments `execute_assignment_or_comment_command` in `src/executor/command_prepare.rs` carried an arm that discarded any simple command whose first expanded word starts with `#`, reporting exit code 0. GNU bash treats comments as purely lexical (parse.y:3630-3643): the reader discards a `#` only when it begins a word in the source text where a word can start. Quoted, expansion-produced, command-substitution-produced and variable-carried `#...` words are command names and report command-not-found (127). Source-text comments never reach the executor as words because the scanner consumes them, so the arm had no legitimate input and is removed (4 lines). Captain verification (Simular box, per-stem result lines): - Pin stem issue3020_hash_command_word: base e1afd25 3 passed / 6 failed (exactly the six quoted/expansion/comsub/variable cells) -> head 9 passed / 0 failed. - Pin stem issue2683_same_line_shopt_extglob: 10 passed / 0 failed on head and on base (see the attribution note below). - Neighbour stems all green: issue3205 11/11, issue1114 13/13, issue1573 9/9, issue120 4/4, audit_b4 1/1. - Lib: head 1207 passed / 0 failed / 4 ignored; base identical; failure name sets empty on both sides. - `RUSTFLAGS="-D warnings"` check at lib+bins scope: rc=0. The all-targets scope is red on base and head alike from pre-existing warnings in unrelated test files (untouched by this change); left for their owners. - `cargo fmt --check` rc=0; marker-literal lint OK. CI on the head: 10 pass + 1 skipping, zero red. ## Note on the second issue The same-line shopt/extglob pins were re-measured: all 10 pass on the current base. Captain attribution check: the pin stem scores 8 passed / 2 failed at f7aee5c (the two failed cells are exactly the banked ones) and 10 passed / 0 failed at f7fed21, the merge commit of PR #3223, whose deferred extglob parking, grouped-feeder entry snapshot and parse-loop marker arming cover the same mechanism. This PR therefore carries no product change for that side; its closure is the captain's manual call on this evidence. ## 本 PR 删除了什么 Removed the 4-line executor arm described above (one `if` block in `src/executor/command_prepare.rs`). Nothing else is deleted; no test files change (the pins are already on master via PR #3163). Fixes #3020 Refs #2683
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.
Refs #3205
问题
同一读单元内
shopt -s extglob在行内执行之前就改变了该单元后段的词法:shopt -s extglob && echo !(bbc)(脚本文件):GNU 在读时以单元入口的门(关)解析整表,!(是否定子 shell,(处报读错误 rc=2、无 stdout;rubash 旧行为把!(bbc)当 extglob 排除模式求值,rc=0 输出 glob 结果。shopt -s extglob; !(bbc)(命令位):GNU 读为否定子 shell,运行时bbc: command not found、后续行继续执行;rubash 旧行为在读时即以模式语义处理。GNU 口径:一个读单元在执行任何部分之前已被完整读入,整单元的词法由单元开始时的选项态决定(parse.y 读时
extended_glob)。修法(读单元级不变量,无个案特判)
extglob_toggled检测标记保持即时置位。GroupGatherInfo::entry_extended_glob),重词法化结束后恢复;交互 stdin 调用点传None(无分组快照语义)。不按连接符逐段取实时态,不对 extglob 或
!(形状做特判。本 PR 删除了什么
无删除。本 PR 为纯增量修法(4 文件 +170/−40,差额为被替换的即时翻转逻辑);未删除任何公开 API、测试或文档。
验证摘要
tests/issue3205_read_unit_extglob_snapshot.rs(11 格,期望值全部对 GNU bash 5.3.20 oracle 在钉内同形布置下实测):9cbe0293+ 仅钉):4 过 / 7 红,红格恰为简报集 {x4, x1b} + 扩展格 {z1, m2, y3, v7, w9};对照格(x0b 无 shopt、上行 shopt、-c内嵌换行、;参数位)全绿。cargo test --locked --lib= 1206 过 / 0 红 / 4 忽略(失败名集为空)。bash:不符而整茎环境形红,基底同样如此,与本改动无关)。RUSTFLAGS="-D warnings" cargo check --locked --lib:rc=0 无警告。(--all-targets下 issue660 测试文件有一处unused import: std::io::Write,已核基底同形存在,属既有、与本 PR 无关。)cargo fmt --check干净;scripts/check-marker-literals.pyOK;scripts/check-utf8-boundary-hygiene.shclean;改动文件无 CR。范围外(已确认不属本单)
+(a|b[)*的]EOF 症状属 [upstream] Parser: unbalanced[inside an extglob group is a fatal parse error and silently truncates the script #2647。shopt -u后,已按门开读入的模式节点在执行期被实时态臂拒绝;GNU 回退字面展开)——已在车道报告中记录,未在本 PR 处理。