Skip to content

fix(parser): ! } is a syntax error, not a command (rubash#3648) - #3766

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3648
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3648

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Summary

GNU rejects a lone } after a reserved-position ! as a syntax error (rc 2); rubash ran } as a command name, reported it not found, and the ! flipped the failure to rc 0 — a bogus command ran and the script continued as if it had succeeded.

$ bash -c '! } { }'
bash: -c: line 1: syntax error near unexpected token `}'
bash: -c: line 1: `! } { }'
rc=2
$ rubash -c '! } { }'
rubash: line 1: }: command not found
rc=0

Fixes #3648 (found as a residual of the #3639 oracle matrix, PR #3646; the ! here is in a reserved position, so the #3639 history-demotion fix cannot reach it).

Root cause

The } arm in src/parser/token_actions.rs gated on command_is_empty only. The ! arm had already toggled inverted, so the command was no longer empty and the } fell through to word handling. The fix admits a pending inversion (command_is_pending_inversion) in the } arm — the same predicate command_allows_compound_start already uses for reserved positions. The arm's existing same-line pop + source echo then match GNU exactly, including suppressing echo ok; ! }'s ok and everything after ! } ; echo hi.

Regression tests

tests/issue3648_bang_brace_regressions.rs (9 tests: seed, bare, in-group, suppress-following, suppress-same-line, multi-line echo, double-bang, script file, legal-bang guard). Fail-first on the base: 7 fail, 2 pass (! ! } and the legal guard already behaved); 9/9 pass with the fix. cargo test --lib: 1249 passed, 0 failed.

Neighbor suites (stash before/after对照)

Failure sets are identical on the base and the fixed tree — 0 new failures: issue332 2/10, issue360 6/3, issue390 1/8, parser_coproc_tests 28/3, parser_tests 312/4 (all pre-existing box artifacts: hardcoded bash: argv0 expectations and the like); issue1840 8/8 green.

Out of scope (verified divergent on the base, left for follow-ups)

  • ! fi / ! then / ! done / ! esac / ! do / ! else / ! elif run the word as a command (rc 0, GNU rc 2) — the sibling reserved-word arm has the same empty-only gate.
  • ! time } / time ! } likewise run } as a command — the } there follows a time prefix, not a pending inversion.

Notes

GNU rejects a lone `}` after a reserved-position `!` as a syntax error
(rc 2); rubash ran `}` as a command name, reported it not found, and the
`!` flipped the failure to rc 0 -- a bogus command ran and the script
continued as if it had succeeded (`! } { }`, `! }`, `{ ! } }`).

Root cause: the `}` arm in src/parser/token_actions.rs gated on
command_is_empty only. The `!` arm had already toggled `inverted`, so the
command was no longer empty and the `}` fell through to word handling.
The fix admits a pending inversion (command_is_pending_inversion) in the
`}` arm -- the same predicate command_allows_compound_start already uses
for reserved positions. The arm's existing same-line pop + source echo
then match GNU exactly, including suppressing `echo ok; ! }`'s `ok` and
everything after `! } ; echo hi`.

Regression tests: tests/issue3648_bang_brace_regressions.rs (9 tests: seed,
bare, in-group, suppress-following, suppress-same-line, multi-line echo,
double-bang, script file, legal-bang guard). Fail-first on the base: 7
fail, 2 pass (`! ! }` and the legal guard already behaved); 9/9 pass
with the fix. cargo test --lib: 1249 passed, 0 failed.

Out of scope (verified divergent on the base, left for follow-ups):
`! fi` / `! then` / `! done` / `! esac` / `! do` / `! else` / `! elif`
run the word as a command (rc 0, GNU rc 2) -- the sibling reserved-word
arm has the same empty-only gate; `! time }` / `time ! }` likewise run
`}` as a command -- the `}` there follows a `time` prefix, not a pending
inversion.

Neighbor suites (stash before/after对照, failure sets identical on the
base and the fixed tree -- 0 new failures): issue332 2/10, issue360 6/3,
issue390 1/8, parser_coproc_tests 28/3, parser_tests 312/4. All are
pre-existing box artifacts (hardcoded `bash:` argv0 expectations and
like); issue1840 8/8 green.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做 area:parser lexer/parser: heredoc collection, comsub body re-parse, quoting state labels Nov 16, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 16, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thank you for the PR, @arookieofc-ai.

Per the owner's rule the captain reviews external PRs first — this is an intake first-pass read, and the PR is queued for captain review. No merge and no changes requested from me.

What I verified on this pass:

  • Home fits. It Fixes [parser] ! } { } runs } as a command instead of a syntax error #3648 (owner-filed, P3-low, area:parser, gnu-baseline, 1.5.1 parser wave; a residual of the [bug] Trailing unquoted { } after ! is folded into one word "{ }" #3639 oracle matrix via fix(lexer): record argument-position ! as Word in reader history (Refs #3639) #3646). The diff scope matches the claim: one widened condition in the } arm of src/parser/token_actions.rs plus the new 9-test regression file tests/issue3648_bang_brace_regressions.rs.
  • Mechanism checks out at source level. command_is_pending_inversion exists in the tree (token_actions.rs, parse_loop.rs) and is the same predicate command_allows_compound_start already uses for reserved positions, as the body states. The stated reason the old gate missed it (the ! arm had already toggled inverted, so command_is_empty was false) is consistent with the diff.
  • CI red is pre-existing, not this PR. The three failing checks (Rust tests, Rust tests macOS, GNU regression goldens) all fail on the single known lib-precondition test api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell ("no rubash binary found", rubash#3292); everything else passes. Note the new nail stem is not in CI's nextest table, so the claimed fail-first 7/2 and 9/9 rest on the author's local run pending the captain's re-run.
  • Scope is explicit. The out-of-scope siblings (! fi / ! then / ! done / ! esac / ! do / ! else / ! elif, and ! time } / time ! }) are documented as verified-divergent and left for follow-ups.

Two points for the captain's review: (1) confirm the 9/9 + fail-first claims on a re-run, and the author's neighbour-suite claim of zero new failures; (2) decide whether the out-of-scope ! <reserved-word> siblings get follow-up issues, since they share the same empty-only gate in the sibling arm.

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3766 第1轮 — 建议:PASS
head: 594ed2c base(merge-base): 0c95350 文件: 2 个 +195/-2
关联 issue: #3648(状态:open,我核过的时间:2026-11-16 18:05 UTC)

机制核查:

  • 成立。GNU 语法 pipeline_command: BANG pipeline_command(third_party/bash/parse.y:1408-1413,toggle CMD_INVERT_RETURN)与 BANG nullcmd_terminator(parse.y:1445 起)只允许 ! 后跟 pipeline_command 或终止符;} 是闭合 { } 组的保留字,不是合法 pipeline_command 起始 → ! } 必为语法错误,诊断走 report_syntax_error(parse.y:6833-6865)并回显违规行。rubash 侧根因:! 分支已 toggle inverted,旧 } 分支只查 command_is_empty,} 落成普通命令词后被取反成 rc 0。本 PR 把门放宽为 command_is_empty || command_is_pending_inversion(src/parser/token_actions.rs } arm),与 command_allows_compound_start 已用的 pending-inversion 判定同源(同文件 1145/1191 行附近)。
  • diff 无可疑/无关改动:仅 token_actions.rs 一个条件 + 新增钉文件 tests/issue3648_bang_brace_regressions.rs(180 行)。无桥接/翻译层/半成品修法。

腿(逐项给数字与名字):

  • 钉自跑:issue3648_bang_brace_regressions head 9 passed / 0 failed(bare_bang_brace_is_syntax_error、bang_brace_inside_group_is_syntax_error、bang_brace_suppresses_same_line_command、bang_brace_suppresses_following_command、double_bang_brace_is_syntax_error、legal_bang_positions_stay_legal、multiline_bang_brace_echoes_offending_line_only、script_file_bang_brace_is_syntax_error、seed_bang_brace_is_syntax_error 全 ok)
  • fail-first:base 0c95350 上同钉 2 passed / 7 failed,红名 = {bare_bang_brace_is_syntax_error, bang_brace_inside_group_is_syntax_error, bang_brace_suppresses_same_line_command, bang_brace_suppresses_following_command, multiline_bang_brace_echoes_offending_line_only, script_file_bang_brace_is_syntax_error, seed_bang_brace_is_syntax_error},base 失败形态为 }: command not found rc=0(} 被当命令执行),与 issue [parser] ! } { } runs } as a command instead of a syntax error #3648 描述一致;绿名 = {double_bang_brace_is_syntax_error(! ! 缺操作数本就报错), legal_bang_positions_stay_legal}
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1351 passed/1 failed/4 ignored)/ base 失败名集 {同}(1351 passed/1 failed/4 ignored)/ 差集 ∅(issue2084 为本机 Windows 基线,双侧同现)
  • -D warnings:cargo check --locked --lib --bins 0 警告通过;--tests 全量在 tests/issue2473_procsub_operand_marker_regressions.rs:29 unused import 处失败——该文件不在本 PR diff 内,merge-base 上同样存在,属预存基线警告;本 PR 两个文件自身无警告
  • 卫生:rustfmt --edition 2021 --check 两文件 clean;check-marker-literals.py OK(117 registry consts, 268 allowlisted sites);check-utf8-boundary-hygiene.sh clean
  • CI(head 594ed2c):红 = GNU regression goldens and canaries / Rust tests / Rust tests (macOS) 三个 job,逐一核日志均为单测 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(前置条件 "no rubash binary found",rubash#3292 签名)= 已知基线;其余 job 全 pass(API ledger tripwire、Compatibility CLI、Shell functionality、Cross-target ×2、Windows compile check、niubash builds)
  • GNU 对照:WSL /usr/local/bin/bash = Bash 5.3.20(1)-release,探针脚本 target/u2_3766_probe.sh(LF 脚本文件喂 bash):! } / ! } ; echo hi / echo ok; ! } / ! ! } / { ! } } → GNU 全部 syntax error near unexpected token '}' + 违规行回显 + rc=2;! { echo in; } / { ! echo in; } / ! (true) → rc=1(合法取反)。rubash head 钉断言同形状全绿 → 一致。Windows/WSL 平台差异不涉及本语法面。

F 点:无

续作记录:无(本轮未改代码)

范围外已知残差(PR 正文已披露,本审计复核属实,留 follow-up):! fi、! then、! done、! esac、! do、! else、! elif、! time } / time ! }、x=1 ! } 在 head 上仍与 GNU 分歧——同属 } arm 之外的兄弟保留字臂,建议队长裁定是否开 follow-up issue。

未跑/VOID 的腿:无

备注:本 PR 下有一条 2026-11-16T06:55:37Z 的 captain intake 评论(id=6909642787,"queued for captain review"),距本审计约 11 小时;调度方补充明确本批「已过 24h,正常审计」,故按指令完成审计,仅供队长知悉。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3766 第2轮 — 建议:PASS(已合并 squash 98d71b8b2d4a5ebe16a1de379ac51ad6bde97e7e)
head: 594ed2c90c5ebcab104a4e1e1aeba077d71648c9(自 U2 未变)base(merge-base): 0c95350c5d117f586f9a0f64f3002da2715a66ea
关联 issue: #3648(closed,2026-11-17T01:35Z completed)

V 波收网复核:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:parser lexer/parser: heredoc collection, comsub body re-parse, quoting state bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[parser] ! } { } runs } as a command instead of a syntax error

2 participants