Repository navigation
Apply the same ECMA to PCRE pattern replacements everywhere - #943
Merged
DannyvdSluijs merged 5 commits intoOct 16, 2026
Merged
Conversation
DannyvdSluijs
force-pushed
the
fix-917-ecma-pcre-replacements
branch
2 times, most recently
from
September 23, 2026 19:40
173c1c2 to
4dc8d16
Compare
DannyvdSluijs
force-pushed
the
fix-917-ecma-pcre-replacements
branch
from
September 30, 2026 14:35
4dc8d16 to
4263721
Compare
DannyvdSluijs
left a comment
Collaborator
There was a problem hiding this comment.
Nice work, it took me some time to get to the bigger PR's but I'm trying to make some time for them now. I did have some remarks though, hope you can process them?
This changes would resolve some test that are currently skipped. Can you also enable them as well to block future regression?
draft6 (lines 359–362)
359: '[draft6/optional/ecmascript-regex.json]: \d in patternProperties matches [0-9], not unicode digits: non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO) is expected to be invalid',
360: '[draft6/optional/ecmascript-regex.json]: \w in patternProperties matches [A-Za-z0-9_], not unicode letters: literal unicode character in json string is expected to be invalid',
361: '[draft6/optional/ecmascript-regex.json]: \w in patternProperties matches [A-Za-z0-9_], not unicode letters: unicode character in hex format in string is expected to be invalid',
362: '[draft6/optional/ecmascript-regex.json]: pattern with non-ASCII digits: non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO) is expected to be valid',
draft7 (lines 365–368)
365: '[draft7/optional/ecmascript-regex.json]: \d in patternProperties matches [0-9], not unicode digits: non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO) is expected to be invalid',
366: '[draft7/optional/ecmascript-regex.json]: \w in patternProperties matches [A-Za-z0-9_], not unicode letters: literal unicode character in json string is expected to be invalid',
367: '[draft7/optional/ecmascript-regex.json]: \w in patternProperties matches [A-Za-z0-9_], not unicode letters: unicode character in hex format in string is expected to be invalid',
368: '[draft7/optional/ecmascript-regex.json]: pattern with non-ASCII digits: non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO) is expected to be valid',
draft2019-09 (lines 374–377)
374: '[draft2019-09/optional/ecmascript-regex.json]: pattern with non-ASCII digits: non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO) is expected to be valid',
375: '[draft2019-09/optional/ecmascript-regex.json]: \w in patternProperties matches [A-Za-z0-9_], not unicode letters: literal unicode character in json string is expected to be invalid',
376: '[draft2019-09/optional/ecmascript-regex.json]: \w in patternProperties matches [A-Za-z0-9_], not unicode letters: unicode character in hex format in string is expected to be invalid',
377: '[draft2019-09/optional/ecmascript-regex.json]: \d in patternProperties matches [0-9], not unicode digits: non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO) is expected to be invalid',
DannyvdSluijs
approved these changes
Oct 16, 2026
The nine copies of createPregMatchPattern() are removed in favour of EcmaPatternConverter, which walks the pattern instead of replacing substrings: - a shorthand class inside a bracket expression is expanded into ranges, so "[\w-]" no longer becomes the broken "[[A-Za-z0-9_]-]"; - an escaped backslash is no longer read as the start of a shorthand class; - an escaped slash is no longer escaped a second time.
…9-09 The EcmaPatternConverter now correctly handles \d, \w and non-ASCII digit patterns, so the 12 corresponding tests can be enabled. Draft4 still uses raw PCRE without conversion, so its tests remain skipped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DannyvdSluijs
force-pushed
the
fix-917-ecma-pcre-replacements
branch
from
October 16, 2026 13:52
757a7bc to
420bf32
Compare
Roman3349
added a commit
to Roman3349/json-schema
that referenced
this pull request
Oct 17, 2026
Bring Draft 2020-12 in line with the changes merged into main since the branch was created: - Support unevaluatedProperties (jsonrainbow#931). $dynamicRef is not followed, the same way $recursiveRef is not in Draft 2019-09. - Use EcmaPatternConverter for pattern, patternProperties, additionalProperties and unevaluatedProperties (jsonrainbow#943). - Add error path and ECMA pattern tests (jsonrainbow#967, jsonrainbow#943). - Drop skip list entries that now pass, including the bignum float comparisons fixed by jsonrainbow#982. Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Roman3349
added a commit
to Roman3349/json-schema
that referenced
this pull request
Oct 24, 2026
Bring Draft 2020-12 in line with the changes merged into main since the branch was created: - Support unevaluatedProperties (jsonrainbow#931). $dynamicRef is not followed, the same way $recursiveRef is not in Draft 2019-09. - Use EcmaPatternConverter for pattern, patternProperties, additionalProperties and unevaluatedProperties (jsonrainbow#943). - Add error path and ECMA pattern tests (jsonrainbow#967, jsonrainbow#943). - Drop skip list entries that now pass, including the bignum float comparisons fixed by jsonrainbow#982. Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Roman3349
added a commit
to Roman3349/json-schema
that referenced
this pull request
Oct 24, 2026
Bring Draft 2020-12 in line with the changes merged into main since the branch was created: - Support unevaluatedProperties (jsonrainbow#931). $dynamicRef is not followed, the same way $recursiveRef is not in Draft 2019-09. - Use EcmaPatternConverter for pattern, patternProperties, additionalProperties and unevaluatedProperties (jsonrainbow#943). - Add error path and ECMA pattern tests (jsonrainbow#967, jsonrainbow#943). - Reject a trailing newline in idn-hostname (jsonrainbow#990). - Drop skip list entries that now pass, including the bignum float comparisons fixed by jsonrainbow#982. Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
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.
Closes #917.
The issue asks for a decision on the commented-out replacements. Rather than pick one, here is what each line does, measured against PCRE on PHP 8.5.
\d→[0-9]/u, PCRE's\dmatches U+0663٣; ECMA-262 defines\das ASCII only\D→[^0-9]\w→[A-Za-z0-9_]/u, PCRE's\wmatchesé; ECMA's does not\W→[^A-Za-z0-9_]\p{digit}→ …\p{digit}outright,preg_match()returns false\p{Letter}→\p{L}So none of them is dead weight: each one exists because PCRE and ECMA disagree, and leaving it out changes what a schema means.
The bug it causes today
\dis commented out inAdditionalPropertiesConstraintbut active inPatternPropertiesConstraint, and the two are consulted for the same property name. Onmain:{"patternProperties": {"^\\d+$": {"type": "string"}}, "additionalProperties": false}{"٣": "ok"}is accepted. Per ECMA\dis[0-9], so٣matches no pattern, is an additional property, and should be rejected.{"5": "ok"}is accepted either way. This is now covered by a test per draft, each of which fails without the change.\p{digit}The two mappings in the tree are not equivalent, so this was not just a cosmetic inconsistency.
[0-9]drops non-ASCII digits,\p{Nd}keeps them, and\p{Nd}is what the ECMA property actually means. I converged on\p{Nd}, which is whatAdditionalPropertiesConstraintalready used.One line I am not comfortable deciding for you
\s→[\s\x{200B}]widens\sbeyond ECMA rather than narrowing it to match: U+200B isCf, notZs, so ECMA's\sdoes not include it. I kept the mapping exactly asPatternConstrainthas it today, sopatternbehaviour is unchanged, but propagating it to the other files does widen them. If the zero width space handling was added for a concrete reason, a comment saying so would settle it; if not, dropping it everywhere would be the more faithful reading. Happy to do either in a follow-up.One parser instead of nine
str_replace()callsReview showed that a plain
str_replace()breaks patterns it should not touch, and thatpatternwas already affected on main:[\w-]became[[A-Za-z0-9_]-], and[\d.],[^\d], an escaped backslash (\\d) and an escaped slash (a\/b) all failed to match.The nine copies of
createPregMatchPattern()are now a singleJsonSchema\Tool\EcmaPatternConverter(marked@internal), which walks the pattern instead. Inside a character class a shorthand expands to ranges (\Dand\Wbecome explicit code point ranges), escapes are kept as they are, and only an unescaped/is escaped for the delimiter.EcmaPatternConverterTestcovers 20 cases, 8 of which fail on the oldstr_replace().Full suite green at 9850 tests on PHP 8.5, including the official JSON-Schema-Test-Suite. PHPStan clean, php-cs-fixer clean on the touched files.