Skip to content

fix(executor): thread quote context into the #/% silent gate for list subjects - #3624

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3581-quoted-removal-gate
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3581-quoted-removal-gate

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3581.

Problem. Quoted "${a[*]#...}" / "${*#...}" with a single "" element was silent; GNU diagnoses bad substitution for the pattern word.

GNU anchors. subst.c:10133-10140 — a quoted-null list element carries QUOTED_NULL, so the removal gate's *value == '\\0' test (subst.c:10320-10327, case '#': case '%':) sees a non-empty word and expands the pattern. The gate's empty half therefore must be defeated by quoting ONLY for list subjects (@, *, name[@], name[*]): scalars/elements/bare names produce no QUOTED_NULL and stay silent quoted or not; an absent list stays silent either way. Heredoc bodies count as quoted context — GNU diagnoses "${a[*]#bad}" there too (Q_HERE_DOCUMENT behaves quoted for list forms) and abandons the command (execute_cmd.c:5522 -> redir.c do_redirections in the forked child).

Change.

  • pattern_word_is_silent gains a quoted flag; list-subject arms use empty_is_silent && !quoted.
  • The ${} fragment's quote context is read from EXTQUOTE_NAME_QUOTED_CONTEXT (in_double || double_quoted || heredoc recorded at each embedded-walker dispatch, rubash#2650) — extended to also fold in the lexer's QUOTED_EXPANSION_SITE marker on $ expansions it saw inside quotes (the fragment's GNU quoted bit).
  • The mutable embedded walker upgrades a fragment's Unquoted context to DoubleQuoted when its own in_double/quoted_site marks the fragment as quoted (mirror of the &self walker).
  • with_forked_heredoc_expansion now carries parameter_bad_substitution across the fork-emulation restore like the arithmetic latches — previously a bad substitution inside a heredoc body printed the diagnostic but the command still ran.

Verified. Byte-identical to GNU bash (5.1 oracle on this Linux box) on the full matrix: quoted/unquoted × list/scalar/element/bare-name × absent/empty/nonempty, plus heredoc bodies. New pin: tests/issue3581_quoted_removal_gate_regressions.rs (8 tests); issue3501_pattern_word_silent (68) still green.

… subjects (Refs #3581)

A quoted "${a[*]#...}" / "${*#...}" with a single "" element must
diagnose a bad substitution inside the pattern word: GNU marks the
quoted-null list element QUOTED_NULL (subst.c:10133-10140), so the
removal gate's empty test (subst.c:10320-10327) sees a non-empty word.
rubash's gate read the joined "" as silent either way.

- pattern_word_is_silent gains a 'quoted' flag; only the LIST-subject
  arms (@, *, name[@], name[*]) treat quoted as absent-only-silent —
  scalars/elements carry no QUOTED_NULL and stay silent quoted or not;
  an absent list stays silent either way (all GNU-verified).
- The ${} fragment's quote context is read from
  EXTQUOTE_NAME_QUOTED_CONTEXT (embedded_parameters' in_double ||
  double_quoted || heredoc record, rubash#2650) — heredoc counts as
  quoted (Q_HERE_DOCUMENT; GNU diagnoses "${a[*]#...}" in heredoc
  bodies too) — and the lexer's QUOTED_EXPANSION_SITE marker, now folded
  into that record at both walkers' $ dispatch.
- The mutable walker upgrades a fragment's Unquoted context to
  DoubleQuoted when its own in_double/quoted_site says the fragment is
  inside quotes (mirror of the &self walker's record).
- with_forked_heredoc_expansion now carries parameter_bad_substitution
  across the fork-emulation restore like the arithmetic latches: GNU's
  do_redirections runs in the forked child (execute_cmd.c:5522), so a
  heredoc-body bad substitution abandons the command (rc 1), it does
  not run with an empty expansion.

Verified byte-identical to GNU bash on the full matrix: quoted/unquoted
x list/scalar/element/bare-name subjects x absent/empty/nonempty, plus
heredoc bodies ("..." and bare).

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 #3624 第1轮 — 建议:PASS
head: 735619d base(merge-base): 27e1d0d 文件: 12 个 +263/-26
关联 issue: #3581(状态:open,我核过的时间:2026-11-16 本地)

机制核查:

  • pattern_word_is_silent 新增 quoted:只有 list 主语(@/*/name[@]/name[*])的「joined 空词」静默分支被 quoting 击穿,标量/元素/裸名不受影响。GNU 依据成立:subst.c:10132-10142 的 var_is_null 在 quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES) 且 QUOTED_NULL(temp) 且数组引用时才把 null 判为非空;subst.c:10320-10327 的 case '#': case '%': 门槛直接看 value/temp 首字节,所以带 QUOTED_NULL 的 list 值会展开 pattern 并报 bad substitution。
  • 引用上下文来源自洽:EXTQUOTE_NAME_QUOTED_CONTEXT(in_double||double_quoted||heredoc)沿用 [upstream] Expansion: nested $'name' (extquote) as a parameter name is rejected inside ${...#...} patterns #2650,并在 embedded walker 里补了 lexer 的 QUOTED_EXPANSION_SITE(fragment 的 quoted bit);heredoc 的 parameter_bad_substitution latch 随 fork-emulation 恢复,对应 GNU execute_cmd.c:5522 在子进程 redir.c do_redirections 里丢弃命令。
  • 无关改动:无。全部 12 文件都在 [bug] 带引号的 "${a[@]#...}" 单 "" 元素应诊断,rubash 静默(#3501 残差) #3581 面(gate 参数线程化 + 两个 quote-context 记录点 + 调用点签名)。正文缺「本 PR 删除了什么」一节(-26 行是签名/格式化),仅记录,不影响机制。

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

  • 钉自跑:issue3581_quoted_removal_gate_regressions 8 passed / 0 failed。
  • fail-first:base 27e1d0d 上 4 passed / 4 failed,红名 = {quoted_star_list_with_empty_element_diagnoses, quoted_scalar_at_list_with_empty_element_diagnoses, quoted_positional_star_with_empty_element_diagnoses, heredoc_body_list_pattern_diagnoses_and_aborts_command},正好是 4 个「应诊断」格;4 个「应静默」对照格在 base 上本来就绿 = 与 PR 声称一致。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {同左} / 差集 ∅(Windows-env 基线,与本 PR 无关)。
  • -D warnings:cargo check --tests 在无关的 issue1331_1334_signal_and_startup 上撞到既有 Windows-only function run_script is never used dead_code;本 PR 文件 0 新增警告。
  • 卫生:fmt rc=0(12 文件逐个 rustfmt --check);marker-lint OK(117 registry consts / 268 allowlisted);utf8 脚本本轮未跑(脚本名不存在于 scripts/)。
  • CI:红的任务 = Rust tests / Rust tests (macOS) / GNU regression goldens and canaries;红名逐个 = api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(说明:唯一已知基线 issue2875),无其它红名。
  • GNU 对照(WSL GNU bash 5.3.20 /usr/local/bin/bash,脚本文件):8 个钉脚本逐条复跑,GNU stdout/stderr 与钉期望逐字节一致(s1 两条 *a=${-y}: bad substitution + rc1=1/rc2=1;s2 同;s3 一条;s4 XY/CD rc0 无诊断;s5 AB/CD/EF rc0;s6 三条静默 rc0;s7 heredoc 两条诊断且 cat 未执行 rc=1/rc2=1;s8 foo yfoo/x y)。PR 正文写的是 5.1 oracle,我用 5.3.20 复核结论相同。
  • 邻域:issue3501_pattern_word_silent 68 passed / 0 failed。

F 点:无。

未跑/VOID 的腿:

  • utf8-boundary 卫生脚本:仓库 scripts/ 下无该文件,VOID。

@caomengxuan666
caomengxuan666 merged commit 9cc6034 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