Repository navigation
Limit uri-template literals to RFC 6570 characters - #1385
Conversation
|
Review of this PR (head 1. Other characters RFC 6570 excludes from literals are still accepted (
Tag characters in U+E0000-E0FFF are accepted the same way. Section 2.1 allows only the listed ASCII ranges, 2. 2.x needs its own port ( |
Full suite with this commit passes, including the 24 |
|
Review of head 1. The pattern overflows the stack on long input ( 2. The new literal class is slower ( 3. CHANGELOG heading ( 4. Redundant test ( 5. Gaps in the sweep ( |
Formats.java and UriTemplateFormatTest are again identical to networknt#1385: runs of literal characters and varchars are matched possessively, so long templates no longer overflow the stack, and the tests add long-input and stray brace or percent sign cases. The two FormatValidatorTest cases are removed, as UriTemplateFormatTest covers the same inputs. The CHANGELOG entry names 2.0.8 and links networknt#1387, networknt#1385 and networknt#1275, and a Fixed entry covers the stack overflow.
Full suite with this commit: 11,132 tests, 0 failures, 57 skipped. |
|
Review of head What I checked:
Two small points remain: 1. Test helper ( 2. Class-alternating input is still slower than master ( |
5164970 to
2c0b245
Compare
RFC 6570 section 2.1 excludes the space and the backslash from template literals, but the uri-template pattern accepted both. Add them to the excluded characters, add a unit test, and update the vendored uri-template.json suite files (draft 6, 7, 2019-09, 2020-12 and draft-next) to the current JSON-Schema-Test-Suite.
Address review: the literal class now lists RFC 6570 section 2.1's ranges (the ASCII characters, ucschar and iprivate) instead of excluding a few characters. C1 controls, lone surrogates, noncharacters, U+FFF0 to U+FFFD and U+E0000 to U+E0FFF are rejected in a literal. The apostrophe stays valid, as in the JSON-Schema-Test-Suite. UriTemplateFormatTest checks the pattern against a predicate written from the RFC's ABNF for every code point, and covers the reviewed examples directly.
The uri-template pattern recursed once per character, so a 5,000-character literal or a 1,000-character variable name threw StackOverflowError. Runs of literal characters and of varchars are now matched possessively, which needs no stack per character. The literal set is unchanged: the ASCII, BMP and supplementary characters are three classes, and the ASCII class lists its characters one by one so java.util.regex compiles it to a bit set. UriTemplateFormatTest adds long-input cases, which overflow the previous pattern, and rejects a stray brace or percent sign. FormatValidatorTest.uriTemplateRejectsSpaceAndBackslashInLiteral is removed, as UriTemplateFormatTest covers the same inputs. The CHANGELOG entry moves to Breaking changes, and a Fixed entry covers the stack overflow.
I've also rebased onto master after #1384, so the CHANGELOG conflict is resolved: both entries now sit under Breaking changes. |
Port of networknt#1385 to 2.x, together with networknt#1275, which was not backported. The literal class lists RFC 6570 section 2.1's ranges (the ASCII characters, ucschar and iprivate). A space, a backslash, C1 controls, lone surrogates, noncharacters, U+FFF0 to U+FFFD and U+E0000 to U+E0FFF are rejected in a literal. The apostrophe is accepted, as in the JSON-Schema-Test-Suite and on master, so both branches agree on uri-template. The vendored uri-template.json suite files are updated.
Formats.java and UriTemplateFormatTest are again identical to networknt#1385: runs of literal characters and varchars are matched possessively, so long templates no longer overflow the stack, and the tests add long-input and stray brace or percent sign cases. The two FormatValidatorTest cases are removed, as UriTemplateFormatTest covers the same inputs. The CHANGELOG entry names 2.0.8 and links networknt#1387, networknt#1385 and networknt#1275, and a Fixed entry covers the stack overflow.
|
Review of head
The class-alternating slowdown stays, as you said. It only affects templates that switch script almost every character, and typical templates are faster than master, so I do not object. |
* Limit uri-template literals to RFC 6570 characters on 2.x Port of #1385 to 2.x, together with #1275, which was not backported. The literal class lists RFC 6570 section 2.1's ranges (the ASCII characters, ucschar and iprivate). A space, a backslash, C1 controls, lone surrogates, noncharacters, U+FFF0 to U+FFFD and U+E0000 to U+E0FFF are rejected in a literal. The apostrophe is accepted, as in the JSON-Schema-Test-Suite and on master, so both branches agree on uri-template. The vendored uri-template.json suite files are updated. * Address review: re-port the #1385 review fixes, CHANGELOG links Formats.java and UriTemplateFormatTest are again identical to #1385: runs of literal characters and varchars are matched possessively, so long templates no longer overflow the stack, and the tests add long-input and stray brace or percent sign cases. The two FormatValidatorTest cases are removed, as UriTemplateFormatTest covers the same inputs. The CHANGELOG entry names 2.0.8 and links #1387, #1385 and #1275, and a Fixed entry covers the stack overflow. * Address review: drop "as on master" from the CHANGELOG entry
Limit uri-template literals to RFC 6570 characters
The
uri-templateliteral class was[^\p{Cntrl}"%<>\^`{|}]. It accepted the space and the backslash, and because\p{Cntrl}covers only U+0000-001F and U+007F, it also accepted C1 controls, lone surrogates, noncharacters and other characters RFC 6570 section 2.1 excludes.ucscharandiprivate, with pct-encoded triplets matched as before. Newly rejected in a literal: the space, the backslash, C1 controls, lone surrogates, noncharacters (U+FDD0-FDEF and the last two code points of every plane), U+FFF0-FFFD and U+E0000-E0FFF.%20and%5Cstay valid. Ranges are listed explicitly rather than using\p{Cn}, becauseucscharallows unassigned code points and\p{Cn}would make the result depend on the JDK's Unicode version.a'bvalid, so it stays accepted (uriTemplateAllowsApostropheInLiteral).UriTemplateFormatTestchecks the pattern against a predicate written from the RFC's ABNF for every code point U+0000-10FFFF as a literal, and lists the rejected and accepted examples directly. It calls the format, not a schema, so lone surrogates don't depend on the JSON parser.StackOverflowError(the old pattern recursed once per character). The ASCII literals are a separate class listed character by character, whichjava.util.regexcompiles to a bit set; ASCII templates match about twice as fast as on master.UriTemplateFormatTest.longTemplatesDoNotOverflowTheStackcovers inputs up to 1,000,000 characters, andrejectscovers a stray brace or percent sign. The backslash case isn't in the upstream suite yet (Add uri-template cases for the remaining characters RFC 6570 excludes from literals json-schema-org/JSON-Schema-Test-Suite#1260 adds it).optional/format/uri-template.jsonfiles for draft 6, 7, 2019-09, 2020-12 and draft-next to the current upstream suite. The draft-next copy keeps this repository's$schemaURI.2.x port: #1387 (also carries #1275, which isn't on 2.x).