Repository navigation
fix(assignment): restore \x18 escaped-quote carrier in quoted-assignment fast path (niubash #103) - #108
Merged
Conversation
…e quoted fast path (niubash #103) The word lexer emits \x18 for `\"` inside double quotes (the niubash #99 family of quote carriers). Command-argument expansion restores it, but the quoted-assignment fast path in executor/assignment_expansion.rs restored only the $ / backtick / backslash / ANSI-C carriers - the \x17 (`\'`) and \x18 (`\"`) escaped-quote carriers were left raw in the stored value. Result: `x="q\"q"` stored q<CAN>q (0x18) - length intact, exit status 0, no diagnostic, and the bad byte survives into redirected files (`printf '%s' "$x" > out` writes 71 18 71). niubash v1.1.1 was correct because the lexer did not emit the carrier yet; the #99 fix introduced it without extending this restore chain. Restore both carriers alongside the others. Safety argument is the same as for the existing restores: a $'...' value never contains a raw carrier (the ANSI-C decoder octal-escapes every control byte into a U+E000 pair), so a raw \x17/\x18 here is always a lexer carrier, never data. Regression tests: tests/assignment_quote_roundtrip_regressions.rs covers single/multiple escapes, propagation through parameter expansion, ${x:-none}, heredoc bodies, and byte-exact redirected output. Known pre-existing issue NOT in this patch (reported in niubash#103 as a side note): compound array elements go through a different path (normalize_single_element_array_assignment strips the outer quotes of `arr=("q\"q")` without resolving the inner escape, storing q\"q; the unquoted `x=(q\"q)` drops both characters, storing qq). GNU stores q"q in both cases. Follow-up needed in parameter_decode.rs / normalize_single_element_array_assignment. 🤖 Generated with [WorkBuddy](https://workbuddy.cn)
…-backslash sh_double_quote Compound array elements ran quote removal twice. The raw token first had its backslash escapes decoded (`\"` -> data `"`), and the partially_quoted pass then ran remove_shell_quotes over the DECODED text, which re-parsed the data quote as an operator pair and stripped it. The order is now the GNU one: remove_shell_quotes over the raw token (leaving escaped quotes as \x17/\x18 data carriers), restore the carriers, then unquote. This matches the storage-side behavior of quote.tests array6.sub and fixes niubash #103 side findings against GNU bash 5.3.0(1) (WSL oracle): x=(q\"q) stored qq now q"q (71 22 71) x=("q\"q") stored q\"q now q"q x=('a"b') read back a\"b now a"b x=("a\"b") read back a\"b now a"b x[1]=c\"d read back c\"d now c"d The read-back half came from quote_array_value / quote_assoc_display_key escaping a bare `"` as `\\"` (two backslashes) where shquote.c sh_double_quote emits `\"`; the doubled backslash survived the storage round-trip as a spurious literal byte. The declare storage path already used the single-backslash form (storage.rs quote_double) and was correct. Known remaining gap (pre-existing, not addressed here): an ANSI-C `$'...'` element whose decoded value contains a quote reaches the storage split with a bare untagged `"` (the upstream decoder does not emit the E010/ E011 markers on this path), so remove_shell_quotes treats it as an operator pair: x=($'a"b') stores ab instead of a"b. Tests: 3 new cases in tests/assignment_quote_roundtrip_regressions.rs; cargo test --lib 397 passed; cargo fmt --check and scripts/check-utf8-boundary-hygiene.sh clean.
caomengxuan666
added a commit
that referenced
this pull request
Sep 16, 2026
…as-char sites - README/README.zh-CN: new "Fixed today" section covering niubash #106 (CRLF line-terminator handling), #107 (-c GNU first-non-option-argument), #108 (type output capture), plus the nameref/history convergence and the debug-instrumentation cleanup from the local batch landing. - check-utf8-boundary-hygiene: extend the execution_misc.rs allowlist entry with the two reviewed byte->char widening patterns introduced by the batch: `out.push(byte as char)` under the 0x20..=0x7e printable-ASCII arm and the octal digit math `b'0' + ((byte >> n) & 0o7)` (always 0x30..0x37) — both can never involve a UTF-8 continuation byte.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
niubash #103 (v1.1.2 regression): escaped double quotes inside a quoted assignment store the raw lexer carrier byte instead of the literal character:
Root cause
The word lexer emits control-byte carriers for escaped characters inside double quotes (\x18 for \", \x17 for \'). Command-argument expansion restores these, but the quoted-assignment fast path in
src/executor/assignment_expansion.rsonly restored \x1f ($), \x1a (backtick), \x14 (backslash) and the ANSI-C markers — missing \x17/\x18, so the carrier byte leaked into storage.This is a side effect of the #99 quote-carrier rework.
Fix 1 — scalar fast path (3f23f8d)
Add the two missing carrier restorations to the fast path. All reporter scenarios verified byte-exact vs GNU bash 5.3.0(1) (WSL oracle): single/multiple escapes, propagation,
${x:-none}, heredoc, redirected output.Fix 2 — array element side findings (742a544)
The issue's array variants had two further bugs, both fixed here after differential testing against the WSL GNU 5.3.0(1) oracle:
\"-> data"), thenremove_shell_quotesran over the decoded text and re-parsed the data quote as an operator pair. Reordered to GNU's sequence: quote removal on the raw token, carrier restore, then unquote.x=(q\"q):qq->q"q;x=("q\"q"):q\"q->q"qquote_array_value/quote_assoc_display_keyescaped"as\\"(two backslashes) instead of\", so the storage round-trip surfaced a spurious backslash:x=('a"b'),x=("a\"b"),x[1]=c\"dall read back with\". Now single-backslash, matching the declare storage path.Verification
tests/assignment_quote_roundtrip_regressions.rs.cargo test --lib: 397 passed.cargo fmt --check+scripts/check-utf8-boundary-hygiene.shgreen.Known remaining gap (pre-existing, separate)
An ANSI-C
$'...'element whose decoded value contains a quote reaches the storage split with a bare untagged"(upstream decoder does not emit the E010/E011 markers on this path), so quote removal treats it as an operator:x=($'a"b')storesabinstead ofa"b. Broken before this PR; will file separately.Closes unixwin/niubash#103 (rubash side).