Skip to content

fix(executor): dual quote-state for subscript ANSI-C spans + unset operand quote-removal (rubash#847) - #857

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

caomengxuan666 merged 1 commit into
masterfrom
fix/847

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #847 (both faces).

Face 1 — E3b: the #822 decode_ansi_c_spans scanner lacked double-quote state

decode_ansi_c_spans tracked only in_single, so a $\$'...'$ span inside double quotes was decoded anyway: master stored the merged prexpost for M["pre\$'x'post"]=w.

GNU's expand_word_internal never recognizes ANSI-C quoting inside dquotes — the whole spelling is data and the key stays pre$'x'post (70726524277827706f7374), verified identical on the assignment entry, the ((...)) entry and the ${...} reader (the reader self-read gr and the arith-write variable read missed on master; both hit after the fix).

Fix: mirror the #839 dual-state law (transform_arith_ansi_c_spans) into decode_ansi_c_spans — $\$'$ opens a span only outside both quotes, '/" toggle their own state only outside the other quote. Bare (E3) and sq-piece (E1) shapes are untouched and pinned as non-regressions.

Face 2 — u-family: unset's deferred operand pass decoded quoted-source $\$'...'$ spellings

unset 'A[\$'"'"'x\\ty'"'"']' / unset "A[\$'x\\ty']" — GNU 5.3.0 keeps the $\$'...'$-written cell (the CR Nit 2 divergence #839 pinned); rubash decoded the span, resolved the stored clean key and deleted the cell.

Fix: quote_remove_ansi_c_spans (same dual-state scanner law) — GNU's deferred pass quote-removes the spelling: quotes drop, the span dollar stays literal, content rides verbatim, so A[\$'x'] resolves the key $x (discriminating probe: with a literal $x cell present, that cell is the one deleted). Non-regressions pinned: the bare spelling still decodes at word expansion and deletes (g1/V7), the variable spelling still expands and deletes (u5), and a $k operand without a span still expands from a single-quoted source (P3).

Carry-out: carrier decode on the arith entry

A kept span on the ((...)) entry stored a raw \x17 carrier mid-key (master's variable-spelling read of ((G["pre\$'x'post"]=1)) missed). expand_assoc_subscript_once now dequotes the final key through decode_word_position_carriers (the subst.c:4807 dequote_string port other word-position consumers already use).

Out of scope (observed during probing, pre-existing on master, left for follow-ups)

  • unset 'A4[\\\ty]' with x unset: rubash reports [\\\ty]: bad array subscript (mask-before-expand folds $x+\\ty into $xty → empty key); GNU keeps silently (nonempty key). No span involved — mask/expansion ordering, its own ticket.
  • kvlist self-read K=( ["pre\$'x'post'"]=v ) stores the right listed key bytes but the same-spelling read misses (hidden bytes in the kvlist dequote path). kv= write row is parity on master and here; the read face is unchanged by this PR.
  • bare-escape adjacency forms (r08/r09/r11) stay pinned per fix(arithmetic): normalize assoc subscripts on the ((...))/let entry (rubash#828) #839.

Verification (WSL GNU bash 5.3.0 oracle, three-way GNU / master b79e678 / fix)

row GNU 5.3.0 master b79e678 fix/847
M["pre\$'x'post"]=w key bytes 70726524277827706f7374 70726578706f7374 (prexpost) 70726524277827706f7374
reader self-read ${G["pre\$'x'post"]} after ((...)) write 1 empty 1
unset 'A1[\$'"'"'x\\ty'"'"']' / u2 dq / u3 dq-escaped cell kept cell deleted cell kept
literal $x cell + unset "C[\\\$'x']" deletes $x, keeps x keeps both (misses) deletes $x, keeps x
E3 / E1 / bare-unset / variable-unset non-regressions — pass pass
  1. Oracle: the full probe matrix (E3b × assignment/arith/reader, u1/u2/u3, bare/variable/param unset, literal-dollar hit) is byte-identical GNU vs fix; the two residual rows above are master-equal.
  2. Suites: tests/issue828 39/39 (25 fix(arithmetic): normalize assoc subscripts on the ((...))/let entry (rubash#828) #839 pins + 14 new/updated incl. the flipped CR Nit 2 pin), tests/issue734 15/15; full cargo test --no-fail-fast -- --test-threads=1 bidirectional vs pristine b79e678: zero new failures, zero flipped (24 failures on both sides, all machine-state: partial Niubash toolchain — opt/niugit/git.exe missing, tilde-user passwd faces — plus the known-flaky executor::path cache test that flaked only on the master run).
  3. Catalog: new issue-847 case + manifest row (must-match), full runner 36/36 against declared expectations; issue-734 row flipped to must-match on catalog PROMOTE (verified matching already on pristine b79e678). cargo fmt --check clean; RUSTFLAGS="-D warnings" cargo build --release clean. Master advanced during the branch (build(package): exclude target-variant dirs from the crate — guard against >10MiB upload rejection #851/test(interactive): pin (A;B);) stray-close family to GNU 5.3.0 across all modes (#845) #852) — merged and re-verified.

…erand quote-removal (rubash#847)

Two faces left in the span-state family after #839:

1. E3b - the #822 assignment/reader decode_ansi_c_spans scanner tracked
   only single-quote state, so a span INSIDE double quotes was decoded
   anyway: master stored the merged prexpost for M["pre$'x'post"]=w.
   GNU's expand_word_internal never recognizes ANSI-C quoting inside
   dquotes - the spelling is data and the key stays pre$'x'post
   (70726524277827706f7374) on the assignment entry, the ((...)) entry
   and the ${...} reader alike. Mirror the #839 dual-state law into
   decode_ansi_c_spans: $' opens a span only outside both quotes,
   '/" toggle only outside the other quote.
2. u-family - unset's deferred operand pass decoded a quoted-source
   $'...' spelling down to the stored clean key and deleted the cell
   (the CR Nit 2 divergence #839 pinned). GNU's deferred
   expand_subscript_string pass quote-removes it instead: the quotes
   drop, the span dollar stays literal, the content rides verbatim
   ($'x' resolves the key $x - gnu9 probe: with a literal $x cell
   present the unset deletes THAT cell) - so u1/u2/u3 keep the
   $'...'-written cell. quote_remove_ansi_c_spans mirrors the same
   dual-state law on mark_arith_span_data carriers; $k-style operands
   still expand (P3 probe) and the bare/variable spellings still
   delete (g1/V7, u5).
3. A kept span on the arith entry landed in storage with a raw \x17
   carrier mid-key - expand_assoc_subscript_once now dequotes the final
   key text through decode_word_position_carriers (the subst.c:4807
   dequote_string port the other word-position consumers use).

Tests: tests/issue828 grows the E3b family (assignment/reader/arith
variable-read rows, dq-adjacency and dq-escaped-backslash shapes, E3/E1
non-regressions) and the u-family rows (u1/u2/u3 keep, literal-dollar
hit, bare/variable/param non-regressions); the CR Nit 2 divergence pin
flips to parity. scripts/regression-catalog gains issue-847.sh + a
must-match row; the stale issue-734 row flips to must-match on catalog
PROMOTE (verified matching already on pristine b79e678).
@caomengxuan666

Copy link
Copy Markdown
Member Author

CR #857 — 独立复核结论:APPROVE-WITH-NITS(无 BLOCKER,可合并;不代合并)

不复述实现者主张,以下全部独立实做(自建 worktree cr-857-review @ c0741a7,基线树 b79e678 另建;未触碰他人 worktree,未 stash)。

1. 双态法则一致性(核心审计)

transform_arith_ansi_c_spans(#839)/ decode_ansi_c_spans(本 PR 改)/ quote_remove_ansi_c_spans(本 PR 新增)逐行 diff:同一律成立 —— $' 仅 !sq && !dq 开跨度、' 仅 !dq 切换、" 仅 !sq 切换、跨度内首个未转义 ' 闭合、未闭合原样落码。唯一微差:外层 \ 对跳过 — transform/quote_remove 无条件,decode_ansi_c_spans 带 !in_single 门(#822 先在,本 PR 未改)。构造探针判真伪:S1['a\'$'x']=w → GNU 615c78 = fix(B 的门是其定义域上的 GNU 正确律);unset "U1['a\'b']"、unset 'U2[$'q'(未闭合跨度)三方全等(A/C 的无条件跳过在探针上不可观测)。差异属定义域差异,不阻合并;建议后续抽公共 scanner 防漂移。

2. GNU 语义核对(WSL 5.3.0 oracle 自跑,三方 GNU/master/fix)

目录 case 11 行逐字节一致;另自设 28 探针(dq 相邻文本、dq 转义反斜杠、跨入口互读、跨度内容含 "/'/backtick、字面 $x 命中、unset -v u3 形、未闭合跨度、空跨度)三方对比:fix == GNU 全部;master 在 E3b 赋值/读/算术三入口、u1/u2/u3、字面-$x-命中、Q1/Q5 载体格上发散——正是本 PR 修的三面。unset -v "U6[\$'x\ty']"(P11)master 主动删格、fix 修正为 keep,此格 PR 测试未钉,顺带验证通过。

3. Face ③ 位置正确性

expand_assoc_subscript_once 返回值直接进 encode_arithmetic_assoc_key 的字节级 hex 传输,中间无其他消费者——在返回前 decode 即终键反引,正确。其余 6 个 decode_word_position_carriers 调用点均为终值消费者(heredoc/command-words/redirect-operand/herestring/pipeline),本次新增与 GNU subst.c:4807 dequote_string 的 word-position 语义同类,无中间态破坏。Q1/Q5(跨度内容含 "/backtick 的键删除命中)证明 ExpandedOnce 尾部载体完整解码、不漏不重。

4. 目录 PROMOTE 复核

b79e678 干净树 build 后跑 cases/issue-734.sh:match(case 文件本 PR 未改,只动 manifest 行)→ 行切换主张成立。

5. 回归

  • tests/issue828 39/39,tests/issue734 15/15。
  • 目录全量 36/36 按声明(25 match + 11 declared-diverges,issue-847 新行 must-match 达成)。
  • 全量双向 --no-fail-fast -- --test-threads=1(fix vs 纯 b79e678):两侧失败集相同(cli_tests 23 + regression.rs 6 + issue526 2 + issue647/680/705/path_contract 各 1,全机器态);base 侧 lib.rs 偶发一例复跑 689/689 通过 → flaky,非切换。零新增零切换成立。
  • cargo fmt --check 干净;RUSTFLAGS="-D warnings" cargo build --release 干净。

6. 夹带扫描

merge-base diff 恰 6 文件(2 src + 1 unset + 2 tests/catalog + manifest);无进程/杀进程面;GPL:注释仅引 GNU 源码行号坐标,无源码拷入。

NITS(非阻塞)

  1. unset_arrays.rs:deferred 在 arrayref 分支白算一次(scanner 对无 $' 文本是纯透传,代价可忽略)——可移入 else。
  2. -D warnings 干净的主张范围是 lib+bins:cargo check --all-targets -D warnings 在两侧同样爆(issue566 unused Path、issue621 dead_code —— b79e678 已有,本 PR 未触)。防后来者误读,建议 CI 化时注明范围。

残余差异立票判断(应立)

PR "Out of scope" 两项均真实、master 相等(已复核),但目前均无 open issue 跟踪,而本 PR 合并即关 #847 —— 建议立即立票,症状可直接搬运 PR 原文:

  • (a) unset 'A4[$x\ty]' 伪诊断 [$x\ty]: bad array subscript + rc1(GNU 静默 rc0)——用户可见且与 ANSI-C 无关(mask/展开序问题,面更宽);空跨度族 ((U8[$'']=1))(GNU 报 bad array subscript,rubash 静默存空键)应并入同票。
  • (b) kvlist 自读 miss(写 parity、读丢)——静默不可见类,宜尽快。

(复核产物:三方探针脚本 + 双向全量日志在 cr 代理侧存档;本 worktree 及基线 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.

#822 scanner 双引号盲区(E3b 存 prexpost 丢 ANSI-C 跨度)+ unset 操作数双引号形(u1/u2/u3)——#839 CR 搁置族

1 participant