Skip to content

Limit uri-template literals to RFC 6570 characters on 2.x - #1387

Merged
stevehu merged 3 commits into
networknt:2.xfrom
ravismash:fix/uri-template-2.x
Nov 9, 2026
Merged

stevehu merged 3 commits into
networknt:2.xfrom
ravismash:fix/uri-template-2.x

Conversation

@ravismash

@ravismash ravismash commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Port of #1385 to 2.x. #1275 (apostrophes in literals) was never backported, so 2.x rejects a'b while master and the upstream suite accept it. This carries both changes so the two branches agree on uri-template.

  • Same literal class as master: RFC 6570 section 2.1's ASCII characters, ucschar and iprivate, plus the apostrophe. Formats.java is identical to master after Limit uri-template literals to RFC 6570 characters #1385.
  • Adds UriTemplateFormatTest, identical to master: every code point checked against the RFC's ABNF, long inputs up to 1,000,000 characters, and the apostrophe.
  • Runs of literals and varchars are matched possessively, so long templates no longer throw StackOverflowError.
  • Updates the vendored uri-template.json suite files, as on master.
  • CHANGELOG: a Breaking changes entry (the apostrophe is newly accepted on 2.x; the space, backslash and other non-RFC characters, accepted in 2.0.8, are newly rejected) and a Fixed entry for the stack overflow.

Merge #1385 first; this branch is refreshed whenever #1385 changes.

Tested on Java 24: the 74 GraalJS regex test errors (Unsafe.ensureClassInitialized was removed in Java 22) also occur on 2.x without this change; every other test passes.

@codecov-commenter

codecov-commenter commented Nov 8, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (2.x@cf6ab7a). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@          Coverage Diff           @@
##             2.x    #1387   +/-   ##
======================================
  Coverage       ?   81.31%           
  Complexity     ?     2413           
======================================
  Files          ?      210           
  Lines          ?     7478           
  Branches       ?     1409           
======================================
  Hits           ?     6081           
  Misses         ?      959           
  Partials       ?      438           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stevehu

stevehu commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Review of head 1313c46. This is a faithful port: Formats.java, UriTemplateFormatTest and the five uri-template.json files are identical to #1385's. The full 2.x suite passes on JDK 11 and JDK 21 (10946 tests, 0 failures; 17 and 16 skipped), and the changed files compile with --release 8. I could not run Java 8. I found no new defect; most points are inherited from #1385. Most-severe first.

1. Stack depth, inherited (Formats.java:65)
The pattern throws StackOverflowError on a 5000-character literal and on { + 1000 a + }, as on master. Java 8 threads have a small default stack. Fixing it in #1385 (a possessive literal class run) and re-porting is cheaper than patching both branches.

2. Speed, inherited (Formats.java:46)
The union of about 25 ranges matched 2–3.5x slower than the old class in the #1385 benchmark (311 ms vs 89 ms for 20000 matches of a 312-character ASCII template). Resolve together with point 1.

3. CHANGELOG links (CHANGELOG.md:12)
The entry links only #1385. The apostrophe reaches 2.x only through this PR, so link #1387 and #1275, and optionally #1385 for the rationale.

4. Duplicate tests (FormatValidatorTest.java:224)
Both new cases repeat inputs from UriTemplateFormatTest (a b, a\\b, a%20b%5Cc, a'b) and the suite, so a rule change needs two updates.

5. Sweep gaps, inherited (UriTemplateFormatTest.java:59)
It skips %, { and }, and rejects has no a{, a} or a% case. Add them in #1385 first so the port stays identical.

6. Ordering (CHANGELOG.md:12)
The PR says Formats.java is identical to master after #1385, but #1385 is open at 282b4a0 with review points outstanding. If its pattern changes, this branch must be re-ported. Merge #1385 first, then refresh this branch.

ravismash added a commit to ravismash/json-schema-validator that referenced this pull request Nov 9, 2026
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.
@ravismash

Copy link
Copy Markdown
Contributor Author
  1. and 2. Stack depth and speed: re-ported from Limit uri-template literals to RFC 6570 characters #1385. Formats.java and UriTemplateFormatTest are identical to Limit uri-template literals to RFC 6570 characters #1385's new head, so long templates no longer overflow (the long-input test passes with -Xss256k), and ASCII templates match about twice as fast as on master. The changed files compile with --release 8.
  2. The entry links Limit uri-template literals to RFC 6570 characters on 2.x #1387, Limit uri-template literals to RFC 6570 characters #1385 and Allow apostrophe in uri-template literal #1275, and says 2.0.8 and earlier accepted the newly rejected characters. A Fixed entry covers the stack overflow.
  3. Removed both FormatValidatorTest cases. UriTemplateFormatTest covers a b, a\b, a%20b%5Cc and a'b.
  4. rejects now has the stray brace and percent cases, the same as on Limit uri-template literals to RFC 6570 characters #1385.
  5. Agreed: merge Limit uri-template literals to RFC 6570 characters #1385 first. This branch matches Limit uri-template literals to RFC 6570 characters #1385's current head, and I'll refresh it if Limit uri-template literals to RFC 6570 characters #1385 changes again.

@stevehu

stevehu commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Review of head f262242 (the commit since 1313c46). All six earlier points are addressed and I found no code defect.

What I checked:

  • Faithful port. Formats.java and UriTemplateFormatTest are identical to Limit uri-template literals to RFC 6570 characters #1385's current head 5164970, and so are the five uri-template.json suite files.
  • Full 2.x suite. 10998 tests, 0 failures on JDK 8 and JDK 21 (62 and 59 skipped).
  • JDK 8 regex engine. The previous pattern and this one agree on about 10 million generated templates. Templates of 600k to 1.2M characters, including failing tails, run on 64k thread stacks without a StackOverflowError.
  • CHANGELOG accuracy. The "before" description matches the 2.x pattern: it excluded the apostrophe and accepted the space and backslash.

One small point:

CHANGELOG wording (CHANGELOG.md:12)
The entry says "as on master" twice. A 2.x reader cannot tell that "master" means the 3.x line, and the reference ages as master changes. The links to #1385 and #1275 already carry the parity information, so the phrase could say "as in 3.x" or be dropped.

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.
@ravismash
ravismash force-pushed the fix/uri-template-2.x branch from f262242 to e663043 Compare November 9, 2026 15:00
@ravismash

Copy link
Copy Markdown
Contributor Author

Dropped both "as on master" phrases from the CHANGELOG entry. The #1385 and #1275 links carry that information. I've also rebased onto 2.x after #1386. UriTemplateFormatTest still has its repeat helper here for Java 8, and it compiles with --release 8.

@stevehu

stevehu commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Review of head e663043, rebased onto 2.x after #1386. I found no defect and no remaining blocker.

Ready to merge.

@stevehu
stevehu merged commit a77ab92 into networknt:2.x Nov 9, 2026
4 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.

3 participants