Skip to content

fix(executor): stamp expansion-time comsub EOF at construct + body lines + 1 (Refs #3605) - #3675

Merged
caomengxuan666 merged 1 commit into
masterfrom
devin/comsub-word-eof-line
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
devin/comsub-word-eof-line

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

run-braces (braces.tests:57): "${a+'$(''}" with a set — the '...' quotes make $( a literal at parse time, but the ${a+word} word expansion re-processes it as a real command substitution. When the extracted body runs out without a ), rubash reported command substitution: line 57 where GNU reports line 59.

command_substitute re-parses the extracted body via parse_and_execute (string, "command substitution", pflags|SEVAL_NOHIST) (subst.c:7413) with pflags = 0 for a non-interactive script (subst.c:7210 — no SEVAL_RESETLINE). push_stream(0) keeps the script's line_number and line_number-- (evalstring.c:345) backs it up one; the body's own lines plus the EOF read then carry the counter to exec_line + body_lines + 1. rubash stamped current + body_lines - 1 — two short.

Measured on GNU bash 5.3.20: ${a+'$('} at line N reports N+2 for a one-line body, N+3 for a two-line body (${a+'$(x\<newline>y\'}).

Refs #3605 (class B, run-braces — clears the suite's only real diff; the cannot execute binary file noise belongs to #3586).

GNU anchors

  • subst.c:7413 — parse_and_execute (string, "command substitution", pflags|SEVAL_NOHIST).
  • subst.c:7210 — pflags = (interactive && sourcelevel == 0) ? SEVAL_RESETLINE : 0.
  • builtins/evalstring.c:345 — if (lreset == 0) line_number--.
  • parse.y:6891 — yyerror EOF branch reports line_number at EOF.

Verification (macOS arm64, GNU bash 5.3.20 oracle)

  • niubash gate run-braces → PASS (zero diff).
  • Byte-identical vs GNU on: echo "${a-'$(\'}" (line 1 → 3), a=x + echo "${a+'$(\'}" (line 2 → 4), same at line 3 → 5, ${a-word} and ${a+word} forms.
  • New tests/issue3605_comsub_word_eof_line.rs (3 tests).
  • Regression slices: issue1184_f6_backquote_eof, issue2309_heredoc_precheck, issue2999_comsub_suffix_backslash_fold, issue318_eval_eof_diagnostics, issue2404_arith_open_line — all green; cargo fmt --check clean.

Known residual (not this PR)

A $(x\<newline>y\' body inside a '...'-quoted ${} word still reports one short — the walk's dequoted text collapses the \<newline> before the line count. Separate mechanism (the produced comsub body itself would carry the newline); noted for the next pass.

Test plan

  • cargo test --test issue3605_comsub_word_eof_line
  • niubash upstream gate run-braces PASS
  • comsub/heredoc EOF diagnostic regression slices

…dy lines + 1 (Refs #3605)

The ${a+word}/${a-word} path (embedded_mutations.rs) re-processes a
'...'-quoted $( as a live command substitution at expansion; when the
extracted body runs out without a ')' it reported the construct's own
line (current + body_lines - 1) where GNU reports
current + body_lines + 1 — command_substitute re-parses the body via
parse_and_execute("command substitution", subst.c:7413) without
SEVAL_RESETLINE (subst.c:7210), so the base is the script's
line_number-1 (evalstring.c:345) and the body's lines plus the EOF
read carry it +2 past the construct line. Measured on GNU 5.3.20:
one-line body reports N+2, two-line body N+3.

run-braces (braces.tests:57 ${a+'$('\\'}" with a=4 set) reported
'command substitution: line 57' vs GNU's 59; now byte-identical.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3675 第1轮 — 建议:PASS
head: 806dee0 base(merge-base): 96802ca 文件: 2 个 +98/-4
关联 issue: #3605(open,核于 2026-11-16 — 追踪目录 issue,合并不关单)

机制核查:

  • '...' 引号内 '$(' 的字面 $( 在 ${a+word}/${a-word} 词展开时被重新处理为真实 comsub;EOF 报告由 current + source.lines().count() - 1 改为 + source.lines().count() + 1(+2)。对应 GNU:command_substitute 经 parse_and_execute(..., pflags|SEVAL_NOHIST)(subst.c:7413)重解析、无 SEVAL_RESETLINE(subst.c:7210)、push_stream(0) 下 line_number--(evalstring.c:345)、EOF 读再把计数推到 exec_line + body_lines + 1(parse.y:6891 yyerror)。实测 GNU 5.3.20:单行体 N→N+2,符合。
  • 已知残差(正文声明):$(x\<newline>y\' 体内 \<newline> 在 walk 去引用时先折叠,计数差一 — 二阶机制,非本 PR 面。
  • 无关改动/桥接层:无。

腿:

  • 钉自跑:issue3605_comsub_word_eof_line 3/3 绿
  • fail-first:base 上 0 passed / 3 failed,红名与钉内三测试一致
  • lib 双边:head {issue2084_session_end_restores_host_process_state} / base 同 / 差集 {}
  • -D warnings:lib+bins 0;钉 stem 编译 0
  • 卫生:全部文件 rustfmt --check 0 diff(cargo fmt 本机 os error 206,逐文件替代)
  • CI:红 = 3 job 仅 issue2875 基线;census skipped
  • GNU 对照(WSL GNU bash 5.3.20 脚本文件):echo "${a-'$(\\'}"(行1)→ GNU/head command substitution: line 3 一致;a=x+行2 → line 4 一致;行3 → line 5 一致

F 点:无

未跑/VOID 的腿:无

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 08:47
@caomengxuan666
caomengxuan666 merged commit 656a0f8 into master Nov 16, 2026
8 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant