Repository navigation
fix(quote): escape U+2028/U+2029 as $'...' octal in declare -p and ${x@Q} (Fixes #3946) - #4040
Merged
Merged
Conversation
This was referenced Nov 21, 2026
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.
Root cause
In UTF-8 locales, GNU
ansic_shouldquote/ansic_quote(third_party/bash/lib/sh/strtrans.c:230-354) checksiswprint(wc)on wide characters: glibc treatsU+2028(LINE SEPARATOR) andU+2029(PARAGRAPH SEPARATOR) as non-printable (Zl/Zp) so they are emitted as$'\342\200\250'/$'\342\200\251', whileCfformat characters (U+200B,U+FEFF,U+00AD) remain printable raw. Rubash'sis_printable_wide(arrays/storage.rs) andis_ansic_printable(parameter_replace.rs) only checked!ch.is_control(), printingU+2028/U+2029raw.Fix
src/executor/arrays/storage.rs(is_printable_wide) &src/executor/parameter_replace.rs(is_ansic_printable): use!crate::locale::is_glibc_cntrl(ch)(Ccunion{U+2028, U+2029}) sodeclare -pand${x@Q}/${x@K}/${x@k}emit GNU's$'...'octal escapes forU+2028/U+2029.tests/issue3946_ansic_quote_line_paragraph_separator.rs(5 tests).Verification
/usr/local/bin/bash(LC_ALL=C.utf8).rustfmt --edition 2021 --checkclean on all 3 files.cargo test --test issue3946_ansic_quote_line_paragraph_separator: 5/5 pass.What this PR deletes
−5 lines in total: the two old predicate expressions (
!ch.is_control()inis_printable_wideinsrc/executor/arrays/storage.rs, −3 lines with its comment, and inis_ansic_printableinsrc/executor/parameter_replace.rs, −2 lines) and the outdated comment text attached to them. Nothing else is removed; both predicates now delegate to the existing shared modelcrate::locale::is_glibc_cntrl(Cc ∪ {U+2028, U+2029}) instead of testingis_control()alone.Captain verification
Verified by the captain's oracle lane on the cloud host against the real GNU bash 5.3.20 oracle (
~/oracle/bash-5.3.20/bin/bash, self-built 5.3 + patches 001–020), 2026-11-21. PR head1012e90fand pristine baseeb1ce9f2both built on the cloud host (debug, jobs=1).declare -pand${x@Q}print U+2028/U+2029 raw instead of GNU's$'...'octal form #3946'sseed_r138c.sh, 12 checks,LC_ALL=C.utf8): oracle 12/12 PASS; this PR 12/12 PASS; pristineeb1ce9f2fails exactly the 6 defect checks (declare -p / ${x@Q} × U+2028, U+2029, and the mixed value) and passes all 6 controls — the pristine divergence set is the fix face exactly.cmp,LC_ALL=C.UTF-8): the pin-2 shapes (${x@Q}/${x@K}/${x@k}), the pin-5 shapes (array/assoc elements and element@Q), plus added@K/@k× U+2029 and mixed-value@K/@kshapes — PR output byte-identical to the oracle on all three probe files; pristine differs on every separator-bearing line (raw bytes instead of the$'\342\200\250'/$'\342\200\251'form).eb1ce9f2—declare_p_escapes_line_and_paragraph_separators,at_transforms_escape_line_and_paragraph_separators, andarray_and_assoc_elements_escape_separatorsFAILED; the two control tests (c1_controls_stay_octal_escaped,format_characters_stay_raw) passed. On the PR tree all 5 tests pass.The author's WSL byte-compare is thus confirmed against the captain's 5.3.20 oracle; the review's outstanding oracle and fail-first debts are cleared.