Repository navigation
fix(expand): decode ANSI-C quotes in compound assignment parameter-operator words (Fixes #4248) - #4259
Conversation
|
Captain review — needs runtime verification, please hold off merging. The non-POSIX core of this fix is well-evidenced (parse.y:4053-4070, subst.c:4215-4233) and the c1–c11 matrix plus the decoded-syntax-bytes test cover the #4248 faces. CI is clean: census 9 FAIL all known, 0 SIGABRT, goldens only the 2 standing snapshots. But there are two oracle questions the code alone can't settle: R1 (blocking): the POSIX arm contradicts the GNU source. The new test R2 (verify with R1): the Also: the base ( |
|
Captain follow-up — the R1/R2 concerns are withdrawn; this PR now passes the gate, merge after rebase. I ran the deciding probes against the real GNU bash 5.3.20 oracle (cloud), and the oracle proves my read-only review wrong:
Full runtime evidence: new pins 3/3 pass on the PR tree and all 3 go red on base — on base the compound-element Remaining ask, same as before: the base is stale (mergeable=false now), so please rebase onto current master; once mergeable with a fresh CI showing the same known census names, I'll merge it. |
…erator words (Fixes #4248)
fdceb7b to
84a3dcb
Compare
|
Rebased onto current
Fresh CI is running now. |
Summary
Expand ANSI-C
$'...'quoting inside${x:-...}(and sibling parameter-operator RHS forms) within compound array assignment elements, matching GNU Bash 5.3.20 byte-for-byte in both non-POSIX and POSIX modes (Fixes #4248).GNU C Specification
third_party/bash/arrayfunc.c:557(expand_compound_array_assignment()): splits the compound body viaparse_string_to_word_list()(:581) and expands each element viaexpand_words_no_vars()(:610).third_party/bash/parse.y:4053-4070(parse_matched_pair()): translates$'...'inside${...}viaansiexpand(), andparse.y:4030-4036implements Austin Group Interp-221 (double-quoted${...}in POSIX mode keeps$'...'literal).third_party/bash/parse.y:5564-5572(read_token_word()): wraps decoded ANSI-C bytes as quoted data so decoded quotes/whitespace/glob chars do not re-enter shell syntax or field splitting.third_party/bash/subst.c:9777(parameter_brace_expand()),subst.c:7966(parameter_brace_expand_rhs()),subst.c:4462(expand_string_for_rhs()), andsubst.c:4807(dequote_string()).Root Cause & Changes
src/executor/assignment_expansion.rs:${var op word}compound elements through the real braced-parameter expansion path (expand_quoted_parameter_wordwhen double-quoted,expand_wordwhen unquoted) instead of blind.replace("\\\"", "\"").replace("\\'", "'")unescaping (which broke$'e\'f'and dropped quoting context).whole_word_parameter_single_valuefor both element and[sub]=forms.ANSI_C_IFS_GUARDtoIFS_GLUEfor field splitting and decode compound expansion carriers before storage so ANSI-C blanks ($'a\tb',$'a b') remain single elements while outer spaces split normally.src/executor/embedded_parameters.rs:$'...'decode arm in the embedded parameter walker (preserving raw$'...'in heredocs and inside double-quote spans, keeping#828intact), using existingescape_decoded_ansi_c_quotes/escape_decoded_ansi_c_quotes_unprotectedcarrier protection so decoded syntax bytes remain data.src/executor/parameter_words.rs:decode_double_quotes_in_quoted_parameter_wordwith GNUparse.y:4030-4036(Interp-221): keep$'...'literal inside double-quoted${...}in POSIX mode while still decoding unquoted${...}operator words.tests/issues_4200_4299.rs+tests/issues_4200_4299/issue4248_compound_ansic_operator_rhs.rs:$'...'.What this PR deletes
.replace("\\\"", "\"").replace("\\'", "'")string corruption inwhole_word_parameter_single_value(src/executor/assignment_expansion.rs).in_sqPOSIX single-quote-span state indecode_double_quotes_in_quoted_parameter_word(src/executor/parameter_words.rs) that contradicted GNU Interp-221 behavior.Verification
/usr/local/bin/bash) matrix:--posix) 21/21 cases: 100% byte-exact.RUSTFLAGS="-D warnings" cargo check --lib --locked: clean (0 warnings).cargo test --test issues_4200_4299 --locked: 5/5 passed.cargo test --test issues_0600_0999 issue828 --locked: 39/39 passed.cargo test --test regression upstream_suite_slice_snapshots_{quote,nquote,rhs_exp} --locked: all passed.cargo test --lib: 1,447 passed, 0 failed.cargo test --test issues_4200_4299 --locked: 5/5 passed.python scripts/check-rustfmt.py: ok (226 targets).python scripts/check-marker-literals.py: OK.python scripts/check-api-ledger.py: OK (298 symbols).Fixes #4248