Skip to content

test(regex): accept common valid patterns - #1214

Merged
jdesrosiers merged 1 commit into
json-schema-org:mainfrom
kabirvashisht4-glitch:test/regex-valid-syntax
Oct 11, 2026
Merged

jdesrosiers merged 1 commit into
json-schema-org:mainfrom
kabirvashisht4-glitch:test/regex-valid-syntax

Conversation

@kabirvashisht4-glitch

Copy link
Copy Markdown
Contributor

Closes #1213.

After #1210, regex.json had six invalid patterns but only one valid string, ([abc])+\s+$. A checker that rejected ordinary syntax could still pass the whole file. This adds valid cases:

instance what it exercises
"" the empty pattern
a|b alternation
a{2,3} a range quantifier
a+? a non-greedy quantifier
[^a-z] a complemented range class

Why these five

All but "" come from the portable subset the core spec asks schema authors to limit themselves to (the list discussed in #898). Each one compiles in V8 with no flag, with u and with v, and in Python re, Ruby, Perl and Java's Pattern. python-jsonschema, jsonschema-rs and fastjsonschema accept all five as well.

Left out because an engine rejects them: lookarounds and backreferences (RE2-based engines), \p{Lu} (Python re), a{65536} (Perl) and [a-] (V8 with v).

Scope

draft3, draft7, draft2019-09, draft2020-12 and v1, the five drafts that have regex.json. The copies are identical apart from the schema object.

Verification

bin/jsonschema_suite check passes 11/11 with no skips (jsonschema==4.19.0).

Run against the edited draft2020-12 file (18 cases, 12 in draft3):

checker before after
toy checker that rejects "", |, {, +? and [^ 13/13 13/18
python-jsonschema 4.19.0 regex (re.compile) 13/13 18/18
V8 new RegExp(s, "u") 13/13 18/18

No engine I tried fails any added case, so like #1210 this is regression coverage, not a fix for a known-failing implementation. No open PR touches regex.json.

regex.json accepted only one valid string, "([abc])+\s+$", so a checker
that rejected ordinary syntax still passed every case. Add the empty
pattern, alternation, a range quantifier, a non-greedy quantifier and a
complemented range class.

All but the empty pattern come from the portable regex subset in the
core specification, and each is accepted by V8 with no flag, with u and
with v, and by Python re, Ruby, Perl and Java. Lookarounds and
backreferences are left out because RE2-based engines reject them.

Closes json-schema-org#1213
@kabirvashisht4-glitch
kabirvashisht4-glitch requested a review from a team as a code owner October 9, 2026 18:30
@jdesrosiers
jdesrosiers merged commit 8568bcc into json-schema-org:main Oct 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regex: only one valid pattern is tested, so a checker that rejects alternation or quantifiers passes

2 participants