Repository navigation
fix(parser): ! } is a syntax error, not a command (rubash#3648) - #3766
Conversation
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.
|
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:
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 |
|
【WIN-AGENT-AUDIT】PR #3766 第1轮 — 建议:PASS 机制核查:
腿(逐项给数字与名字):
F 点:无 续作记录:无(本轮未改代码) 范围外已知残差(PR 正文已披露,本审计复核属实,留 follow-up): 未跑/VOID 的腿:无 备注:本 PR 下有一条 2026-11-16T06:55:37Z 的 captain intake 评论(id=6909642787,"queued for captain review"),距本审计约 11 小时;调度方补充明确本批「已过 24h,正常审计」,故按指令完成审计,仅供队长知悉。 |
|
【WIN-AGENT-AUDIT】PR #3766 第2轮 — 建议:PASS(已合并 squash V 波收网复核:
|
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.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 insrc/parser/token_actions.rsgated oncommand_is_emptyonly. The!arm had already toggledinverted, 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 predicatecommand_allows_compound_startalready uses for reserved positions. The arm's existing same-line pop + source echo then match GNU exactly, including suppressingecho ok; ! }'sokand 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/! elifrun 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 atimeprefix, not a pending inversion.Notes
!in reserved position (rubash#3647) #3765 ([parser] syntax error after!in reserved position does not echo the source line #3647,!-after-pipe source echo): different arm, no overlapping hunks; this PR is based on master without it.