Repository navigation
fix(regex): accept an escaped endpoint in a character-class range - #139
Merged
Merged
Conversation
A range that started with an escaped character (`[\]-~]`) was parsed as three separate members, so it compiled and silently never matched. A range that ended with an escaped character (`[&-\[]`) returned NotImplemented, which surfaces as the uncatchable unsupported-feature error. parseClassSet now reads every member through parseClassMember, which yields either one character (a plain byte, a UTF-8 codepoint, `\uXXXX` or an escaped literal) or a class escape. Any character may bound a range; addClassRange splits it between the byte bitmap and the codepoint set, so a range may also cross from ASCII into Unicode (`[a-é]`). A `-` before a nested class is a literal, and a class escape as a range end is the catchable invalid-pattern error, both as in java.util.regex. Expected values in the suite and the corpus were read from java.util.regex. Fixes #135
This was referenced Dec 1, 2026
BuddhiLW
added a commit
that referenced
this pull request
Dec 1, 2026
No textual conflicts. build.zig.zon takes staging's version 1.15.9 and keeps this branch's minimum_zig_version, zlinter and zwasm pins. CHANGELOG keeps staging's [1.15.9] section unchanged and its Unreleased entries; the auto-merge had folded this branch's four Zig 0.17.1 / zwasm v2.12.1 entries into [1.15.9], so they are moved back under Unreleased, since they did not ship in 1.15.9. The incoming regex (#139, #142) and require (#141) code uses no API 0.17.1 removed or deprecated, so it builds unchanged: the 0.17 rename pass over src touches nothing, `zig fmt --check` is clean, and the -Dwasm ReleaseSafe build is green. All 171 clj suites pass (1006 tests, 5420 assertions). Smell-audited: 0: merge only; build.zig.zon takes staging's version, no Zig source changed by the resolution
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.
Fixes #135.
The defect
[\]-~], compiled and silently never matched. The parser added the escaped literal as a lone member and went on, so the class became the three members],-and~.[&-\[], did not compile: it returnedNotImplemented, which surfaces as the uncatchable unsupported-feature error (see The regex "not supported" error cannot be caught by try and ends the process #136).The fix
parseClassSetinsrc/runtime/regex/compile.zigreads every member through one function,parseClassMember. It yields either one character (a plain byte, a UTF-8 codepoint,\uXXXXor an escaped literal) or a class escape such as\d. Any character may bound a range.addClassRangesplits the range between the byte bitmap and the codepoint set.That also fixes, as in
java.util.regex:[a-é]), which used to set a byte range up to the first UTF-8 byte;-before a nested class ([a-[b]]), which is a literal;[a-\d]), now the catchable invalid-pattern error.compile.ziggets 6 lines longer overall (104 changed: 55 added, 49 removed).Checks
Built with
zig build -Dwasm -Doptimize=ReleaseSafe(Zig 0.16.0):test/clj/run_suites.clj: 171 suites loaded, 1004 tests, 5410 assertions, 0 failures, 0 errorsscripts/corpus_regression.clj: 5529 of 5529 golden outputs reproduced, including the newregex_class_escaped_range.txttest/e2e/regex_parity_gaps.sh3 of 3,test/e2e/phase14_re_matcher.shpasseszig build testandzig fmt --checkpassEvery expected value in the new suite cases and the corpus file was read from
java.util.regex(through babashka).Not in this PR
test/run_all.sh) was not run locally.Please do not merge before release PR #138 lands: a merge into staging moves its head and restarts both gate jobs.