Skip to content

fix(executor): mark_quoted_ifs_from_raw recognizes markers.rs carrier bytes (#868) - #874

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/868
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/868

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #868. Carries #794's disposition item 3 (carrier-blind quote simulation) to closure; #298's compound transport tag and the #795 \' guard semantics are preserved (their regression suites stay green).

Problem

mark_quoted_ifs_from_raw (src/executor/command_prepare.rs ~4040 at e6a5445) re-parses the raw word with a parallel quote-removal simulator and only applies per-char \x1c IFS marks when the simulated cook equals the actual cooked word; on mismatch it bails into the coarse split-everything-or-nothing fallback. The simulator treated every markers.rs carrier the lexer cook produces ($'...' ANSI-C decode output, $"..." bodies, escaped quotes, escaped IFS blanks and pattern-significant chars) as an opaque data byte — carrier-laden raw words mismatched on every char and silently lost the per-char rule, and pure-carrier words skipped the path entirely.

The full-suite A/B also exposed a second defect in the same function that the ticket's acceptance battery trips over: the apply loop double-marked chars that mark_literal_ifs_chars had already glued. The splitter consumes each glue as "protect the next char", so the doubled glue spent the first glue on the second and released the IFS char itself — with IFS=:, "a:b"$w (and the plain-ASCII 'a:b'$w family) split its quoted colon on master.

Fix

The simulator now replays the lexer walk's carrier arms arm-for-arm (lexer/quotes.rs cursor walk), per the markers.rs registry:

  • backslash escapes (outside quotes) cook to DATA_DOLLAR / DATA_BACKTICK / DATA_SQUOTE / DATA_BACKSLASH / DATA_DQUOTE, consuming both bytes; escaped IFS blanks cook to the self-guarded ANSI_C_IFS_GUARD pair (never re-marked — split sites convert the guard to IFS_GLUE, and a doubled glue would re-release the blank); escaped pattern-significant chars cook to CTLESC pairs;
  • '...' spans cook $ / ` / " to their DATA_* carriers;
  • "..." spans additionally cook ' to DATA_SQUOTE, the glob set * ? [ @ + ! to CTLESC pairs, and a $ that starts no expansion to DATA_DOLLAR (GNU parse.y skip_double_quoted);
  • $'...' decodes through the authoritative pipeline (decode_ansi_c_quoted + escape_decoded_ansi_c_quotes) so the simulation sees exactly the E010/E011/E401/CTLESC quoting the lexer emits;
  • $"..." enters the double-quote rules with the $ dropped;
  • an unbraced $name keeps the walk's pending_name protocol: the next $ / ' / " / \ trigger arm first emits PARAM_NAME_END_MARKER;
  • the apply loop skips an already-glued position (the double-mark fix).

The mismatch bail stays as the safety net for shapes outside these arms; carrier words no longer reach it.

Verification

WSL GNU bash 5.3.0 (/usr/local/bin/bash) oracle, script-file mode, byte-exact both sides:

  1. Ticket probe + boundaries: 45-shape battery (carrier inside/outside the IFS value, nested quotes, multiple IFS separators, pure-carrier words, unset expansions). All 42 shapes owned by this layer match GNU byte-for-byte; the 3 residual diffs (decoded quote vs quote-char-in-IFS; adjacent quoted-$w tail splitting) were verified A/B against master as pre-existing gaps in other layers — base-identical or closer — and are not mark_quoted_ifs_from_raw simulator is carrier-blind: carrier-laden raw words silently lose per-char IFS marking #868 scope.
  2. Regressions: new tests/issue868_carrier_ifs_mark_regressions.rs (7 cases, expectations GNU-verified) + scripts/regression-catalog case issue-868 (diverges on master e6a5445/bd24cf8b, must-match here). No-regression families all green: [bug] Unquoted positional parameter in array assignment is not word-split on IFS: set -- a.b.c; IFS=.; A=($1) gives 1 element (GNU 3) — breaks OMB _omb_util_split / half-life git version compare #298 (12), #789 splitting rework: two field-splitting regressions vs GNU 5.3.0 (nested-quote guard + ${$+<nl>}) #795 (arrdefault + parameter_transform, 23), patsub 替换文本的用户 PUA 码点未 E400 转义,与 PATSUB 标记碰撞(release 可复现)——#838 CR NIT-3 #843 (12), regression(8c52cb7f): wholly-quoted compound-assignment element undergoes pathname expansion — arr=("$x") globs when x='*' #369/[P1] variable assigned via ${V:=default} never word-splits again (breaks bash-it powerline segment loops) #428/[P2] compound-array quoted default ${v:=x y} inside ("${v:=x y}") stores wrong elements (wt66-adjacent family) #432/[bug] inside guard reports SET for unset element; empty quoted element dropped in unquoted slice assignment c=( ${b[@]+"${b[@]:0:2}"} ) — liquidprompt test_array 2/3 fail #315, marker_leak_golden (18) — 107 cases.
  3. Full suite: cargo test --no-fail-fast --test-threads=1 both sides — fix 5606 passed / 37 failed vs base bd24cf8 5598 / 38; failure sets identical except three base-side environment flakes that pass on the branch (part_043 command -p PATH face, part_071 shellmath fixture face, executor::path windows listing cache). Zero new failures. cargo fmt --check clean on both; clippy warning count unchanged (555 pre-existing on both).

Known visible improvements over master (previously wrong vs GNU, now byte-exact): IFS=:; printf '<%s>' "a:b"$w → <a:bx><y>; printf '<%s>' "a b"$'x'$w → <a bxc><d> (the ticket's acceptance probe face); 'a:b'$w, a\:b$w, "a*b"$w under custom IFS, $'\u00e9:'$w and carrier-in-IFS faces.

… bytes (#868)

The #743 per-char IFS marking pass simulated quote removal with a
parallel state machine and bailed without marking on any mismatch. The
simulator treated every markers.rs carrier the lexer cook produces
($'...' ANSI-C decode output, $"..." bodies, escaped quotes, escaped
IFS blanks and pattern-significant chars) as an opaque data byte, so
carrier-laden raw words mismatched on every char and silently degraded
to the coarse split-everything-or-nothing fallback - exactly the words
that most need the per-char rule - and pure-carrier words skipped the
new path entirely.

The simulator now replays the lexer walk's carrier arms arm-for-arm
(lexer/quotes.rs remove_shell_quotes + remove_double_quoted_into_
cursor): backslash escapes cook to DATA_DOLLAR / DATA_BACKTICK /
DATA_SQUOTE / DATA_BACKSLASH / DATA_DQUOTE consuming both bytes;
escaped IFS blanks cook to the self-guarded ANSI_C_IFS_GUARD pair
(never re-marked); escaped pattern-significant chars cook to CTLESC
pairs; single-quote spans cook $, backtick and " to their DATA_*
carriers; double-quote spans additionally cook ' to DATA_SQUOTE, the
glob set to CTLESC pairs and a non-expansion $ to DATA_DOLLAR (parse.y
skip_double_quoted); $'...' decodes through the authoritative
decode_ansi_c_quoted + escape_decoded_ansi_c_quotes pipeline;
$"..." enters the double-quote rules with the $ dropped; and an
unbraced $name keeps the walk's pending_name protocol (the next
$/quote/backslash trigger emits PARAM_NAME_END_MARKER first).

Same function, second defect exposed by the #868 battery: the apply
loop added a second \x1c glue in front of a char mark_literal_ifs_
chars had already marked. The splitter consumes each glue as 'protect
the next char', so the doubled glue spent the first glue on the second
and released the IFS char itself - with IFS=:, "a:b"$w (and the
plain-ASCII 'a:b'$w family) split its quoted colon. Already-glued
positions are no longer re-marked.

The mismatch bail stays as the safety net for shapes outside these
arms; carrier words no longer reach it.

Verification (WSL GNU bash 5.3.0 oracle, script-file mode, byte-exact):
- 45-shape battery (carrier inside/outside the IFS value, nested
  quotes, multiple IFS separators, pure-carrier words, unset
  expansions): all 42 shapes owned by this layer match GNU; the 3
  residual diffs verified against master as pre-existing gaps in other
  layers (decoded quote vs quote-char-in-IFS, adjacent quoted-$w tail
  splitting), base-identical or closer.
- New regressions tests/issue868_carrier_ifs_mark_regressions.rs
  (7 cases) plus scripts/regression-catalog case issue-868 (diverges on
  master, must-match here).
- No-regression: #298/#795/#843/#369/#428/#432/#315/marker_leak_golden
  families all green (107 cases).
- Full suite --no-fail-fast --test-threads=1 A/B against master
  bd24cf8: 5606 passed / 37 failed vs base 5598/38, failure sets
  identical minus three base-side environment flakes; zero new
  failures.
- cargo fmt clean; no new clippy warnings.

closes #868
@caomengxuan666

Copy link
Copy Markdown
Member Author

独立代码评审(CR #874)— 结论:APPROVE-WITH-NITS

独立复验(自建 worktree @ 001a647,未触碰他人树;oracle 为 WSL GNU bash 5.3.0(1) x86_64-pc-linux-gnu,script-file 模式双侧逐字节)。

主张逐项复核 — 全部成立

  1. carrier 逐臂复刻审计(静态,对照 lexer/quotes.rs cursor walk):外层 \ 五类逃逸 carrier(双字节推进)、逃逸 IFS 空白→ANSI_C_IFS_GUARD 自护对、逃逸模式字符集(* ? [ ] @ + ! ( ) | / - ^ . = :)与 quotes.rs:409 逐字一致;'...' 三 carrier;"..." 内 '→DATA_SQUOTE、glob 集→CTLESC、非展开 $→DATA_DOLLAR;${/$( 逐字拷贝臂正确地位于 in_double 分派之前(双引号内展开形不 bail——我最初疑此为回归,实证排除);$name pending_name 协议边界形(${name}、$ 后非名、长名、dquote 收臂发 PARAM_NAME_END_MARKER、dquote 内 '/glob/\ 静默清除)与 walk 一致。
  2. $'...' 委托为真委托:span 提取循环与 decode_ansi_c_span_cursor 逐行等价(含尾随 \ 补齐、非 ASCII char 推进),解码走同一对权威函数(decode_ansi_c_quoted + escape_decoded_ansi_c_quotes);decoded blank 的 guarded-不重记正确。
  3. 第二缺陷(双重护位):实证 master IFS=:; "a:b"$w → <a><bx><y>(错),fix → <a:bx><y> = GNU。prev_glued 实现正确(相邻双 IFS 字符各得一层 glue、已护位不重标、对既有 glue 的尾扫描安全)。
  4. GNU oracle 对照(自建 19 形矩阵 + 4 形残差探针):fix 23 形全部与 GNU 逐字节一致;master@f4d61ca 错 9 形。注意:本机 Niubash/msys bash 5.3.0(1) 在字面冒号拆分("a:b"x:y)上不合 GNU,不可作 oracle——复验者请用 WSL。
  5. bail 安全网:失配 → 原样返回 cooked_with_marks = 修复前行为(代码 + A/B 探针双证)。触发形($(case x in (a) …) 的 ) 早闭、backtick 体 \<newline> 删改、dquote 内 backtick \" 折叠)实测 fix/master 输出全同,无错位标记、无 panic。
  6. 回归:新 7 例 7/7 绿;catalog issue-868 runner GATE ok、verdict match;家族套件绿([bug] Unquoted positional parameter in array assignment is not word-split on IFS: set -- a.b.c; IFS=.; A=($1) gives 1 element (GNU 3) — breaks OMB _omb_util_split / half-life git version compare #298×12、patsub 替换文本的用户 PUA 码点未 E400 转义,与 PATSUB 标记碰撞(release 可复现)——#838 CR NIT-3 #843×12、marker_leak_golden×8、[bug] $'...' unit between two comsubs in one word is folded to a space (echo A$((1+1))B$'\n'C$((2+2))D prints one line; GNU prints two) #379×12、[P1] variable assigned via ${V:=default} never word-splits again (breaks bash-it powerline segment loops) #428×14、arrdefault×11、parameter_transform×18);cargo test --no-fail-fast -- --test-threads=1 双向:fix 5604 通过/39 失败 vs master@f4d61ca7 5616/44,差集全部为本机环境 flake + 评审并行跑 A/B 撞临时目录所致(单独重跑全绿);cargo fmt --check 净;RUSTFLAGS="-D warnings" cargo build 净。
  7. GPL 红线:新增 GNU 引用仅 parse.y:5694 行号引用(quotes.rs 已有同款),无 GPL 代码移植;diff 严格限于 5 个仓内文件,无夹带。

非阻塞备注(NITS / 建议跟进)

  • [同函数第三缺陷,预存,建议另开票] push_quoted_char 记录 simulated.len()(字节偏移),apply 环用字符计数比对——多字节字符在前的引用 IFS 空白位错标:w=W; set -- "é a"$w → rubash <é><aW> vs GNU <é aW>(master 同错,非本 PR 回归;但 carrier 词过门后该面到达面变大)。修法很小(记录 char index)。本 PR 未主张覆盖多字节,不计入 BLOCKER。
  • 预存他层残差(A/B 同错):"${x:-a b}"$w 整引用默认值拆分(GNU <a bW> vs rubash <a><bW>)。
  • bail 盲点(安全方向):backtick 体 \<newline> elision 与 dquote 内 backtick \" 折叠未复刻 → 失配 bail 粗回退;$()/${ 逐字拷贝用朴素深度计数,case 形会早闭(巧合相等时无标记,方向安全)。

不合并(按评审规程由维护者执行)。评审 worktree 已清理。

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.

mark_quoted_ifs_from_raw simulator is carrier-blind: carrier-laden raw words silently lose per-char IFS marking

1 participant