Repository navigation
fix(heredoc): expand heredoc bodies on wordless null commands (Refs #2761) - #3715
Conversation
…2761) A command with redirections but no words at all (a bare <<EOF, or 3<<EOF) went straight from the empty-words arm to execute_empty_words_command, bypassing the stdin pre-expansion funnel (preexpand_command_stdin, the GNU do_redirections point) every word-bearing command passes through, so the body was never expanded: no command substitution ran, no := bound. Route the bodies through that same funnel inside execute_empty_words_command, after the null command's assignments are bound and after the adjudicated assignment-error arms (#2369/#1542/ #402) have had their chance to discard the command first, so the expansion goes through that error handling instead of around it. The funnel classifies the context itself (#2681): an fd-0 heredoc forces the fork boundary (effects run but do not persist), a numbered-fd body expands in the shell (bindings persist); the funsub-exit latch arms mirror the word-bearing path (#2763). Commands without stdin bodies skip this entirely.
|
Thank you, @arookieofc-ai — first-pass intake review from the community bot. The captain reviews external PRs first, so this is not a merge decision; it is a checked read of the diff and the CI, queued for captain review. What I checked
CI, run 43740013432 + canary 43740013543, every cell named
Two things that need a captain decision, not mine
Noted, not filed: the pre-existing word-bearing here-string divergence flagged in the PR note ( Queued for captain review; CI watched. |
|
队长裁断(2026-11-16):感谢提交。#2761 已有更早的在途 PR #3362(Uarz 于 2026-11-11 开,同 issue 的另一实现,18 枚钉),按本仓规矩先审先行 PR,本 PR 暂缓,不并行推进两份实现;若 #3362 不能落地,会回到本 PR 处理,并尽量吸收本 PR 的测试用例。另 #2761 本身卡在 #3578 的合入(其幸存者 #3603 尚在合入轮队列中),该门未开前两支都不会合入。本 PR 不关闭,状态随 #3362 / #3603 的进展更新。CI 已按名:4 红皆为已知基线格(issue2875 + canary 的 ledger 漂移,修补 #3704 / niu #1021 在途),无 PR 专属红格。 |
|
【WIN-AGENT-AUDIT】PR #3715 第1轮 — 建议:FAIL 机制核查:
腿(逐项给数字与名字):
F 点(建议 FAIL 逐条):
续作记录:无(本轮未动代码、未 push) 未跑/VOID 的腿:
|
…c bodies in the shell (Refs #2761) (#3842) The vanished-words arm of the empty-words dispatch passed `cmd` with its raw words (`["$EMPTY"]`) to `execute_empty_words_command`, so the heredoc fork classifier saw an effective word and expanded a numbered-fd body in a fork, discarding `:=`. GNU's words==0 check runs on the EXPANDED word list, which is empty here — the node is a null command, and the force-fork rule (fd-0 / REDIR_VARASSIGN only) leaves a numbered-fd body expanding in the shell, so `:=` persists. Hand the node to the null-command path wordless, as GNU sees it. GNU anchors (audit tree bash-5.3, verified): - execute_cmd.c:4626-4640 — `words == 0` dispatches to execute_null_command. - execute_cmd.c:4210-4216 — force-fork only for REDIR_VARASSIGN or a redirect targeting fd 0 / bash input; fd-3 does not force it. Absorb note: this is the surviving remainder of Uarz #3362 after #3715 merged (487c745). Dropped as already-in-master: both visibility changes (`abort_on_expansion_errors`, `preexpand_command_stdin`) and the `command_prepare.rs` insertion block (superseded by #3715's 61-line version with the funsub-exit latches). `preexpand_command_stdin` keeps master's `Option<i32>` return (the #2763 latch); #3362's `()` signature was NOT taken. Pins trimmed from 17 to the 9 shapes #3715 lacks: the discriminating `vanished_words_numbered_heredoc_assign_persists` (red on master by code trace, green after this hunk) plus eight coverage pins (arithmetic x2, two-heredoc order x2, arith-error x2, fd0-fatal x1, post-alias x1). Verification: no cargo/rustc on this VM and the X299/server routes are down, so no local leg ran. Pin red/green is established by code trace (see REPORT.md); CI census (which runs all stems) adjudicates on the PR. Co-authored-by: Uarz <[email protected]>
Root cause
A command with redirections but no words at all (a bare
<<EOF, or3<<EOF) went straight from the empty-words arm toexecute_empty_words_command, bypassing the stdin pre-expansion funnel (preexpand_command_stdin, the GNU do_redirections point) every word-bearing command passes through. The body was never expanded: no command substitution ran, no:=bound.Fix
Route the bodies through that same funnel inside
execute_empty_words_command, after the null command's assignments are bound and before the #535 redirect-rejection gate:null_command_redirects_force_fork, effects run but do not persist); a numbered-fd body expands in the shell (:=persists). The funsub-exitlatch arms mirror the word-bearing path (executor: heredoc-body funsub exit latch lingers into the next command #2763).preexpand_command_stdinandabort_on_expansion_errorswidened topub(in crate::executor)(visibility only, no behavior change).Evidence (GNU bash 5.2.21 on the box; the issue's oracle is 5.3.20)
<<EOFwith\$(touch se)+${v:=bound}: GNU se=yes; after fix rubash se=yes, v does not persist (fd-0 force-fork per [A1-F08] ${x:=...} in a heredoc feeding an external command persists in the parent shell #2681). Note: on 5.2.21 GNU still binds:=here — bash 5.3 changed the null-command force-fork to cover it; rubash follows the [A1-F08] ${x:=...} in a heredoc feeding an external command persists in the parent shell #2681 model / 5.3 oracle, noted in the test comments.3<<EOF: GNU se=yes v=bound; after fix rubash se=yes v=bound.: 3<<EOFbinds,cat <<EOFexpands in the fork (se=yes, v unset), before and after.readonly ro; ro=x <<EOF: diagnostic + rc=1 + following line runs, body never expands (-c seeded BASH_SOURCE accepts := assignment; GNU fatals on att_noassign #2369/[bug] ${v:=x} 对 readonly 赋值失败退出状态 2 应为 1 #1542 arms untouched; rc=1 verified against GNU 5.2.21 for this exact shape).x=hello <<EOF: body sees x=hello (insertion sits after the assignment loop).\$(false) <<EOF: rc=0, body expands ([bug] empty-word command with heredoc returns comsub status instead of 0 #3021 fork rule kept).Validation
tests/issue2761_heredoc_empty_words_regressions.rs: 11 tests (both forms, quoted delimiter, readonly discard, assignment visibility, bare here-string, vanished words, worded neighbor, both funsub latch arms) — all pass.cargo test --lib: 1249 passed, 0 failed.{ }group does not abandon rest of line (GNU aborts the list) #1318/[bug] Plain-path null command from comsub does not fire the ERR trap (timed form fixed in #1611) #1661/[B2-F06] Redirect-only commands expand redirect words before binding their (permanent) assignments #2718/[bug] empty-word command with heredoc returns comsub status instead of 0 #3021/[B1-01]:?/:=semantics lost outside the main word pipeline (redirect words, arithmetic, case patterns, select lists, subscripts, nested fragments) #2701): all green except 4 pre-existing baseline failures —issue2681 herestring_external_discardsx1 andissue535x3 (input_redirect_word_reports_bare_unbound_name,external_output_redirect_word_is_contained,diagnostic_routes_through_earlier_stderr_redirects) — reproduced on the same baseline e81a1af without this fix with an identical failure set, so 0 new failures.cargo fmt --check,git diff --checkclean. Windows cross-compilation not run (no environment on the build box).Note (found, not fixed here)
A pre-existing here-string divergence on the word-bearing path, unrelated to this null-command fix:
cat <<<\"${v:=bound}\"binds on rubash but discards on GNU (theherestring_external_discardstest above is that failure). It predates this change and lives outside the empty-words funnel; flagging for a separate issue.