Repository navigation
Conversation
JSON Schema defines `pattern` and `patternProperties` as ECMA-262 regular expressions. Julia compiles PCRE with UCP and without DOLLAR_ENDONLY, so `$` matched before a trailing newline and `\d`, `\w` matched Unicode digits and letters. - Compile with DOLLAR_ENDONLY and without UCP: `$` matches only at the end, and `\d`, `\w`, `\b` are ASCII. - Translate `\s` and `\S` to ECMA-262 white space: tab, vertical tab, form feed, every Zs, U+FEFF, and the line terminators. - Map Unicode's extra General_Category aliases (digit, cntrl, punct, Combining_Mark). - Run optional/ecmascript-regex.json from the official suite for each draft, and add unit tests that run by default.
|
@tanmaykm can we get a review of this PR to comply with the semantics for timeseries validation? We've notices that typescript and rust OpenAPI generators are more strict with this standard |
|
Thanks, this looks good. Turning off Escaped brackets change the character-class tracking In SchemaEngine._ecma_pattern("^\\[\\s\\]\$")
# ^\[\t\n\x0B\f\r\p{Zs}
\]$ -- \s expanded as if inside a class
# "[ ]" matched on main, no longer matches
SchemaEngine._ecma_pattern("^[\\]\\s]+\$")
# ^[\][\t\n\x0B\f\r\p{Zs}
]]+$ -- \] ended the class early
# "] " matched on main, no longer matchesConsuming the escaped character in the escape branch should fix both. After Optional, fine as a follow-up: ECMA-262 Behavior note for the release notes: |
- Read each escape as one token. An escaped `[` or `]` no longer changes the class state, so `^\[\s\]$` and `^[\]\s]$` match as in ECMA-262. - Write `\s` and `\S` as explicit ranges of the ECMA-262 white-space set. The ranges work inside a class, so `[\S]` and `[^\S]` are correct. - Translate an unescaped `.` outside a class to exclude every LineTerminator, `[]` to an empty match, and `[^]` to any code point.
Summary
JSON Schema defines
patternandpatternPropertiesas ECMA-262 regular expressions._ecma_regexcompiles them with Julia's default PCRE options. Those includeUCPandlack
DOLLAR_ENDONLY, so several ECMA-262 rules did not hold:^abc$"abc\n"$before a trailing newline)^\d$"߀"(NKO digit zero)UCP)^\w$"é"UCP)^\s$^\p{digit}+$"߀"^a.b$"a\rb","a\u2028b".accepts CR, U+2028, U+2029)^[]$,^[^]$"","\n"]read as a literal)The official suite's
optional/ecmascript-regex.jsoncovers these cases, but it did notrun.
Changes (
src/schema_engine/dialects.jl)DOLLAR_ENDONLYand withoutUCP.$matches only at the end, and\d,\wand\bare ASCII, as in ECMA-262.\p{…}still matches Unicode properties,because it needs only UTF mode.
\sand\Sto explicit ranges of the ECMA-262 white-space set: tab,vertical tab, form feed, the Unicode 16
Zscode points, U+FEFF, and the lineterminators LF, CR, U+2028 and U+2029. The ranges work inside and outside a class, so
[\S]and[^\S]also follow ECMA-262. Julia compiles withALT_BSUX, so code pointsup to U+00FF use
\xhh, other BMP code points use\uhhhh, and U+10FFFF is a literal..outside a class to[^\n\r\u2028\u2029],[]to(?!),and
[^]to(?s:.).[,]or.does not change the classstate.
ECMA_GENERAL_CATEGORIES:digit,cntrl,punctandCombining_Mark.Tests
test/schema_engine/official.jlalso runsoptional/ecmascript-regex.jsonfor eachdraft (2020-12, 2019-09, 7, 6, 4) when
OPENAPI_SCHEMA_SUITE=all. Before this change,the 2020-12 file stops with a compile error at
\p{digit}. The other cases also fail:\d,\D,\w,\W,\s,\S. After it, all 74 tests pass for each draft.test/schema_engine/compiled.jlhas unit tests that run by default: the trailingnewline, ASCII
\dand\w, Unicode\sand\S(also inside a class), escapedbrackets,
.,[],[^],\p{digit}and\p{Letter}.OPENAPI_SCHEMA_SUITE=all julia --project=. -e 'using Pkg; Pkg.test()': "OpenAPI testspassed". 12071 passes, 0 failures, 0 errors.
Official JSON Schema suite: 10624 of 10624.Context
This PR is independent of #135 (
date-time-local). Both come from the Sienna SDK(Sienna-Platform/SiennaSchemas#109), which relies on
patternfor RFC 3339 timestamps.Without
DOLLAR_ENDONLY,"2030-01-01T00:00:00\n"passes a^…$timestamp pattern.