Repository navigation
fix(trap): verbatim trap-action source echo (Refs #3328) - #3483
Merged
Merged
Conversation
Root cause: the six trap-action re-parse sites in src/executor/trap_exec.rs (run_exit_trap_action, run_debug_trap, run_return_trap, run_pending_signal_traps, maybe_run_error_trap_inner, run_sigchld_trap_for_reaped_child) re-parsed the action with the bare parse(), which carries no source text, so the stored __RUBASH_PARSE_SOURCE__ fell back to the token-join reconstruction (`echo inaction ; echo (` for `echo inaction; echo (`). The stored action string itself is verbatim (trap -p proves it); only the diagnostic echo was re-serialized. Fix: thread the action string as ParseLoopOptions::source_text at those six sites — the same shape the eval/comsub re-parses already use. No parser file touched, no other option changed (stray_close_is_error stays false, source_line_offset stays 0). GNU anchors (vendored bash-5.3): trap.c:496 (signal traps, parse_and_execute "trap"), trap.c:1071 (EXIT trap, "exit trap"), trap.c:1109-1200 (_run_trap_internal, DEBUG/RETURN/ERR tags), error.c:300 (parser_error), parse.y:6814 (print_offending_line echoes the input line verbatim). Tests: new tests/issue3328_parse_source_span_fidelity.rs (8 pins: EXIT/DEBUG/RETURN/ERR/USR1/CHLD, a second spacing shape, and an eval control). Pins assert only the echo line (verbatim present, re-serialized form absent); the missing trap-context infix and the rc=2 abort on the DEBUG/RETURN/ERR/CHLD faces are adjacent divergences left for their own lanes. UNVERIFIED-BY-CAPTAIN: not yet compiled or run — no build slot this round (local build banned, box disk full, old server ssh timeout); CI first check and the captain review round must run the new stem, the full lib/base alignment, RUSTFLAGS="-D warnings" check, and the GNU 5.3.20 oracle comparison (local 5.2.21 was reference only). Refs #3328
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。 续作记录:无。 未跑/VOID 的腿:无。 |
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:12
This was referenced Nov 15, 2026
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.
What
Trap-action source echo lines are the parser's re-serialized text instead of
the action's own line:
trap 'echo inaction; echo (' EXITreports`echo inaction ; echo ('where GNU reports`echo inaction; echo ('.The stored action string itself is verbatim (
trap -pproves it) — only thediagnostic echo was re-serialized.
Root cause
The six trap-action re-parse sites in
src/executor/trap_exec.rs(
run_exit_trap_action,run_debug_trap,run_return_trap,run_pending_signal_traps,maybe_run_error_trap_inner,run_sigchld_trap_for_reaped_child) re-parsed the action with the bareparse(), which carries no source text, so the stored__RUBASH_PARSE_SOURCE__fell back to the token-join reconstruction inoffending_line_text(src/parser/parse_loop.rs:3416).Fix
Thread the action string as
ParseLoopOptions::source_textat those sixsites — the same shape the eval/comsub re-parses already use. No parser file
touched, no other option changed (
stray_close_is_errorstays false,source_line_offsetstays 0). Full census of__RUBASH_PARSE_SOURCE__producers/consumers and the no-source re-parse sites is in
fix-3328/REPORT.md§2 (coprocNonesites and the alias-retryPARSE_SOURCE_SPAN__path deliberately left alone: #3267 guardrail and aseparate carrier).
GNU anchors
Vendored bash-5.3 tree, verified line by line:
trap.c:496 parse_and_execute (trap_command, "trap", pflags)trap.c:1071 parse_and_execute (trap_command, "exit trap", pflags)_run_trap_internal(trap.c:1109) →trap.c:1200 parse_and_execute (trap_command, tag, flags)error.c:300 parser_error; verbatim echo:parse.y:6814 print_offending_lineTests
New
tests/issue3328_parse_source_span_fidelity.rs(8 pins: EXIT / DEBUG /RETURN / ERR / USR1 / CHLD, a second spacing shape
echo a;echo(, and an evalcontrol). Pins assert only the echo line (verbatim present, re-serialized form
absent). The missing trap-context infix and the rc=2 abort on the
DEBUG/RETURN/ERR/CHLD faces are adjacent divergences left for their own lanes.
本 PR 删除了什么
无删除。本 PR 是纯加法:六处
parse()→parse_with_options+source_text(+67/−6 行,均为同一调用点的改写),加一个新测试文件。无公开面、无行为面
变更,除 trap 动作解析失败时回显行文本本身。
UNVERIFIED-BY-CAPTAIN
Not yet compiled or run — no build slot this round (local build banned, box
disk full, old server ssh timeout). CI first check and the captain review round
must run the new stem, the full lib/base alignment,
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins, and the GNU 5.3.20oracle comparison (local 5.2.21 was reference only). Note: the X299 direct
lane key was installed during this round (MEMORY.md 2026-11-13 08:2x), so the
review round can run build legs via X299 direct instead of the full box.
Refs #3328