Repository navigation
fix7/locale2: locale defaults, UTF-8 POSIX classes, strict ERE intervals (#1621, #1622, #1658) - #1752
Merged
Merged
Conversation
GNU bash resolves the locale at startup with setlocale(LC_ALL, "") (locale.c set_default_locale, called from shell.c), so with no locale variable set - or all of them empty - the C locale is in effect and character semantics are byte semantics. rubash's is_utf8() kept a default UTF-8 model for the empty-name case, a leftover of the locale port that #1464's explicit-locale fixes never reached: ${#é} counted 1 char instead of 2 bytes and printf %q / ${v@Q} emitted raw UTF-8 instead of $'\303\251'. Flip the empty-name branch of locale::is_utf8() to false; every consumer (length view, quoting escapes, case mapping, =~ granularity) already decides through that one point. With the default corrected, the =~ byte-mode predicate drops its one-surface compensation clause (|| locale_name().is_empty(), from #1061) and is the plain negation. Regression: tests/issue1622_no_locale_default_regressions.rs (env-clear unset case, LANG= case, C.UTF-8 control). Expectations verified against GNU bash 5.3.20.
…s (rubash#1621) Under LC_ALL=C.UTF-8, GNU resolves POSIX character classes through wctype/iswctype (lib/glob/smatch.c for the pattern matcher, regcomp's tables for =~), so É matches [[:upper:]] and é matches [[:lower:]]/[[:alpha:]] on all four surfaces ([[ ]], case, pattern removal, =~). rubash classified with an ASCII-only table everywhere, so multibyte characters never matched any class. The class tables now live in src/locale.rs as the single decision point next to is_utf8(): utf8_posix_class_matches() implements the glibc C.UTF-8 tables as measured against the GNU oracle (digit/xdigit stay ASCII-only; alpha adds non-ASCII Nd digits; NBSP and U+202F are not space; U+3000 is space/blank but not graph; U+2028/U+2029 are space and cntrl; Cf chars are print/graph/punct). NON_ASCII_ND_RANGES (63 ranges) backs both the predicate form and the regex-text form. - pattern.rs posix_class_matches(): byte-carrier mapping unchanged; under is_utf8() it delegates to the new table. The single-byte ASCII table is byte-for-byte untouched (#1533 pins). - =~ (conditional.rs): translate_posix_bracket_classes() takes a unicode_classes flag (text mode only); [:class:] spans expand to Unicode constructs (\\p{Uppercase}, \\p{Alphabetic}+Nd ranges, De Morgan negated classes for print/graph/punct, ledger char sets for space/blank). Byte mode passes classes through unchanged. Regression: tests/issue1621_posix_class_utf8_regressions.rs (four surfaces + measured edge rules under C.UTF-8, LC_ALL=C control). Expectations verified against GNU bash 5.3.20.
[[ a =~ a{,2} ]] silently matched as if the interval were {0,2}:
translate_posix_ere_quantifiers rewrote {,m}/{,} to {0,...} and the
repetition-error scan documented {,5} as a valid interval. POSIX ERE
requires the leading number, and the GNU oracle this was filed
against rejects the pattern at runtime with status 2 and
'invalid repetition count(s)'. (glibc regcomp accepts {,n} as an
extension - the strict reading is the filed expectation; this commit
is self-contained and reverts cleanly if the glibc reading is ever
preferred.)
- Compile gate: posix_ere_has_empty_min_interval() (skips escapes
and bracket expressions, mirrors the bad-interval scan) makes the
pattern fail compilation, i.e. status 2.
- regexp_repetition_error(): an empty minimum after an atom reports
'invalid repetition count(s)'; with no preceding atom it stays
'Invalid preceding regular expression'.
- The {0,...} rewrite in translate_posix_ere_quantifiers is gone,
and the stale doc comments are corrected.
Regression: tests/issue1658_ere_empty_min_interval_regressions.rs
(rc=2 + diagnostic wording; {0,2}/{2,}/escaped-literal controls).
caomengxuan666
marked this pull request as ready for review
October 26, 2026 07:48
This was referenced Oct 26, 2026
Closed
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.
Integration slice for the fix7/locale2 family: three locale/conditional fixes, cherry-picked onto current master with zero conflicts.
src/locale.rs::is_utf8()returnedtruefor an empty locale name (a self-invented default left over from the locale port; [bug] Non-ASCII bytes are emitted raw by @Q, printf %q and declare/export -p instead of $'\ooo' escapes #1464 only fixed the explicit-locale surface). Fix flips the empty-name branch tofalseat the single decision point and removes the compensating|| locale_name().is_empty()patch inconditional_regex_byte_mode()([bug]=~dot matches a full char, GNU matches one byte #1061 residue).[[ == ]],case, pattern removal and=~. Root causes: an ASCII-only predicate table inpattern.rs::posix_class_matches()and the ASCII-only regex crate receiving[:class:]verbatim. Fix converges the class tables intosrc/locale.rs(utf8_posix_class_matches()+NON_ASCII_ND_RANGES, measured against glibc's C.UTF-8 tables with oracle probes); the single-byte ASCII table is byte-for-byte untouched (matcher: glob ? matches a character instead of one byte in C/POSIX locale (pattern removal over multibyte values) #1533 surface).=~translation expands classes to Unicode constructs in text mode only.=~accepted the ERE-invalid empty-minimum intervala{,2}(rewritten to{0,2}). Fix adds a compile gateposix_ere_has_empty_min_interval()→ rc=2 withinvalid repetition count(s), and removes the rewrite. Note: glibc regcomp acceptsa{,2}as an extension; this slice deliberately takes the strict reading for the POSIX-undefined form (bionic regcomp agrees), per the adjudication recorded in DECISIONS.md (2026-10-26). The commit is self-contained and revertible as a whole.Each fix carries its own issue-numbered regression file (
tests/issue1621_*,tests/issue1622_*,tests/issue1658_*), expectations written against the GNU bash 5.3.20 oracle.Verification (integrated tree): full build + 3 new regression files + lib suite (failure set identical to this tree's baseline: only
ownership_unary_operators_check_existing_file) + 13 red-line/sibling pins incl. #1533 C-locale byte pins and #1531 locale watchers, all green;p1621_all_diff.shoracle-vs-rubash diff shows only the expectedre[]ascii/word divergence tracked separately in #1717; diffcorpus 306 failure set ⊆ {ms10}.Fixes #1621
Fixes #1622
Fixes #1658