Skip to content

fix(executor): mark_quoted_ifs_from_raw applies quoted-IFS marks on the recorded byte-offset basis (#876) - #882

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

caomengxuan666 merged 1 commit into
masterfrom
fix/876

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #876. Third defect in mark_quoted_ifs_from_raw from the #874 CR round (pre-existing on master; #874's carrier awareness lets more multi-byte words through the simulation gate, widening the reach — the #874 CR prediction). #874's carrier arms and the #868 double-mark protection land above this fix and are preserved untouched.

Problem

push_quoted_char records quoted IFS positions as simulated.len() — a byte offset — while the apply loop counted one per char. A multi-byte char before a quoted IFS char shifts every later record past the loop's counter, so the \x1c glue never lands on the recorded char and the field splitter releases it:

IFS=' :'; printf '<%s>' "é a"$w   →  rubash master: <é><aW>   GNU 5.3.0: <é aW>
IFS=' :'; printf '<%s>' "中文 a"$w →  rubash master: <中文><aW> GNU 5.3.0: <中文 aW>

The 2-byte é puts the quoted space at byte 2; the loop asked at char 1. Quoted non-whitespace IFS chars were backstopped by mark_literal_ifs_chars, which is why only the whitespace face diverged.

Fix

The apply loop advances its position counter by ch.len_utf8() — the same byte units push_quoted_char records (cooked_pos += 1 → cooked_pos += ch.len_utf8(), plus basis comments). IFS_GLUE keeps being skipped without advancing the counter, so the counter always names the byte offset of the current char in cooked (== simulated, pinned by the equality guard).

GNU spec: quoted source characters are CTLESC-protected during expansion (subst.c:11639-11673) and the field splitter skips them (subst.c:3119 list_string) — protection is per-character and byte-transparent.

Verification

WSL GNU bash 5.3.0 (/usr/local/bin/bash) oracle, cat script | wsl bash -s with tr -d '\0', byte-exact both sides:

  1. Ticket probe + boundaries: 24-shape battery (é/中文/ä/emoji leads × quoted blank/colon/tab × single-quote/escape/nested/ANSI-C-decode/carrier-tail/unset/after-close faces + ASCII controls) — all byte-match GNU; master 41bfdd3 diverged on 11 of the 24.
  2. Regressions: new tests/issue876_multibyte_quoted_ifs_mark_regressions.rs (7 cases, expectations GNU-verified) + regression-catalog case issue-876 (diverges on master 41bfdd3, must-match here). No-regression: mark_quoted_ifs_from_raw simulator is carrier-blind: carrier-laden raw words silently lose per-char IFS marking #868 7 cases + the fix(executor): mark_quoted_ifs_from_raw recognizes markers.rs carrier bytes (#868) #874 family 107 cases ([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 11 + parameter_transform 18, patsub 替换文本的用户 PUA 码点未 E400 转义,与 PATSUB 标记碰撞(release 可复现)——#838 CR NIT-3 #843 12, [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 5, regression(8c52cb7f): wholly-quoted compound-assignment element undergoes pathname expansion — arr=("$x") globs when x='*' #369 7, [P1] variable assigned via ${V:=default} never word-splits again (breaks bash-it powerline segment loops) #428 14, [P2] compound-array quoted default ${v:=x y} inside ("${v:=x y}") stores wrong elements (wt66-adjacent family) #432 13, marker_leak_golden 8) all green.
  3. Full suite: cargo test --no-fail-fast --test-threads=1 both sides vs pristine base 41bfdd3 — fix 5640 passed / 37 failed vs base 5634 / 36 (+7 new tests); failure sets identical except profiler fixture_text_tree_matches_normalized_output, a pre-existing timing flake that also fails standalone runs on pristine base (4/6). Zero new failures. cargo fmt --check clean (fmt also fixed a pre-existing 2-line use-order in command_prepare's test module, required by the fmt hook); rustc check warnings 28/28 base/fix, clippy 549/549 — zero new.

…he recorded byte-offset basis (#876)

push_quoted_char recorded quoted IFS positions as simulated.len() — a BYTE
offset — while the apply loop counted one per char. A multi-byte char before
a quoted IFS char shifted every later record past the loop's counter, so the
\x1c glue never landed on the recorded char and the splitter released it:
with IFS=' :', "é a"$w split into <é><aW> where GNU keeps <é aW> (the 2-byte
é puts the space at byte 2; the loop asked at char 1). The quoted
non-whitespace faces were backstopped by mark_literal_ifs_chars, which is why
only the whitespace face diverged — and #874's carrier awareness lets more
multi-byte words through the simulation gate, widening the reach (the #874 CR
prediction).

The apply loop now advances its counter by ch.len_utf8() — the same byte
units push_quoted_char records. IFS_GLUE keeps being skipped without
advancing the counter, so the counter always names the byte offset of the
current char in cooked (== simulated, pinned by the equality guard). The
#874 carrier arms and the #868 double-mark protection land above this fix
and are untouched.

GNU spec: quoted source characters are CTLESC-protected during expansion
(subst.c:11639-11673) and the field splitter skips them (subst.c:3119
list_string) — protection is per-character and byte-transparent.

Verification (WSL GNU bash 5.3.0 oracle, cat script | wsl bash -s with
tr -d '\0', byte-exact both sides):
- 24-shape battery (é/中文/ä/emoji leads x quoted blank/colon/tab x
  single-quote/escape/nested/ANSI-C-decode/carrier-tail/unset/after-close
  faces + ASCII controls): all byte-match GNU; master 41bfdd3 diverged
  on 11 of the 24.
- New regressions tests/issue876_multibyte_quoted_ifs_mark_regressions.rs
  (7 cases) + regression-catalog case issue-876 (diverges on master
  41bfdd3, must-match here).
- No-regression: #868 7 cases + the #874 family 107 cases (#298 12, #795
  arrdefault 11 + parameter_transform 18, #843 12, #315 5, #369 7, #428 14,
  #432 13, marker_leak_golden 8) all green.
- Full suite --no-fail-fast --test-threads=1 both sides vs pristine base
  41bfdd3: fix 5640 passed / 37 failed vs base 5634 / 36 (+7 new tests);
  failure sets identical except profiler
  fixture_text_tree_matches_normalized_output, a pre-existing timing flake
  that also fails standalone runs on pristine base (4/6). Zero new
  failures.
- cargo fmt --check clean (fmt also fixed a pre-existing 2-line use-order
  in command_prepare's test module, required by the fmt hook); rustc check
  warnings 28/28 base/fix, clippy 549/549 — zero new.

closes #876
@caomengxuan666

Copy link
Copy Markdown
Member Author

Independent CR review of PR #882 (fix/876 @ bfae5df vs base 41bfdd3) — verdict: APPROVE

Full re-verification performed on an isolated worktree (rubash-cr-882 at bfae5df; base rebuilt from pristine 41bfdd3). No blockers found.

1. Diff scope — verified minimal. Exactly one code line (cooked_pos += 1 → cooked_pos += ch.len_utf8()), two comment blocks documenting the byte basis, the new 7-case regression file, the issue-876 catalog case + manifest row, and a 2-line test-module use reorder. No third_party, no process-management code, no GPL content (GNU C is cited by file:line only).

2. Byte-basis audit (core) — correct for all widths. push_quoted_char records simulated.len() before pushing, i.e. the byte offset of that char in simulated; the simulated != cooked guard (string equality = byte equality) pins those offsets to cooked. In the apply loop, IFS_GLUE (1 byte, absent from cooked) is pushed without advancing; every other char advances by its own len_utf8(), so cooked_pos is exactly the byte offset of the current char in cooked for 1/2/3/4-byte chars alike — the manual accumulation is equivalent to cooked.char_indices() (required because iteration runs over the glue-interleaved cooked_with_marks). Grep confirms cooked_pos has exactly one consumer (quoted_set.contains), so there is no second misaligned consumption point left in the function. The #874 carrier arms and the #868 !prev_glued double-mark guard are untouched (diff-confirmed) and stay green.

3. GNU 5.3.0 oracle — re-run independently, byte-exact. WSL /usr/local/bin/bash 5.3.0(1)-release, script files, cmp on raw outputs. 25 faces: 10 sampled from the 24-form battery (é/中文/ä/😀 leads × blank/colon/tab × single-quote/escape/nested/carrier-tail), 7 self-expanded (mid-word é, non-BMP 🎉 lead, mixed 1+2+3+4-byte interleaving, multi-byte IFS value IFS=中 with quoted 中, ASCII controls), 8 mixed-width stress probes ("aé中😀 b c"$w, "ééé a b"$w, "😀😀😀 x"$w, decoded-tab spans, …). Fix is byte-identical to GNU on all 25; master 41bfdd3 diverges on 16 of 25 — including the ticket face ("é a"$w → <é><aW>) and faces where the stale gate even left $w unexpanded (<😀><x$w>), confirming the #874-widened reach and that the fix repairs the class, not just the reproducer.

4. Regressions — all green, run by me. New 7/7; #868 7/7; family per the PR's own enumeration: #298 12, arrdefault 11, parameter_transform 18, #843 12, #315 5, #369 7, #428 14, #432 13, marker_leak_golden 8 = 100/100. Catalog runner: exit 0 on two runs, issue-876 and issue-868 both match. Some loc-*/lim-*/issue-7xx rows flap between runs (pre-existing environmental flake, untouched here — separate triage candidate).

5. Full suite, both directions, --test-threads=1. Fix 5639 passed / 38 failed vs pristine base 5633 / 37 (+7 new tests ⇒ 5640 expected; see flake below). Failure sets are identical except executor::path::tests::windows_nohash_mode_memoizes_hits_but_not_misses, which passes 3/3 standalone on both trees — a load-sensitive Windows cache-timing flake, not a regression.

6. fmt / warnings — clean. cargo fmt --check exit 0; cargo check zero warnings on both trees; RUSTFLAGS="-D warnings" cargo check exit 0. The 2-line use reorder is genuinely pre-existing: rustfmt --check on the base file flags exactly that hunk (fmt is the pre-commit hook), so the piggyback is legitimate and minimal.

Non-blocking notes

Verdict: APPROVE — the record/apply bases are now provably the same units, the guard that backs them (simulated == cooked) is unchanged, and every claim I could test reproduced exactly.

@caomengxuan666
caomengxuan666 merged commit f570150 into master Oct 19, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/876 branch October 21, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant