Skip to content

Add AbstractRFC3987Format and reject characters RFC 3987 does not allow in iri - #1395

Merged
stevehu merged 3 commits into
networknt:masterfrom
ravismash:refactor/rfc3987-format
Dec 3, 2026
Merged

stevehu merged 3 commits into
networknt:masterfrom
ravismash:refactor/rfc3987-format

Conversation

@ravismash

Copy link
Copy Markdown
Contributor

Follow-up to #1390 and #1391. Adds AbstractRFC3987Format, so IriFormat and IriReferenceFormat share the isInternationalized() override and the bidi check. containsBidiFormatting stays on AbstractRFC3986Format, since it's public API.

Also fixes item 1 from the #1391 review: iri and iri-reference now reject private-use characters outside the query, noncharacters such as U+FFFE, and lone surrogates.

iri and iri-reference reject characters that are not ucschar, and
iprivate outside the query, anywhere in the value.
IriFormat and IriReferenceFormat now share the isInternationalized()
override and the bidi check. containsBidiFormatting stays on
AbstractRFC3986Format, since it is public API.
@stevehu

stevehu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks, this looks good. Both issues below are minor, and neither blocks merging.

I ran the format tests and the JSON-Schema-Test-Suite at 3fa21c89, and all 8,325 tests pass. I also compared edge cases against the base commit 2de9814f. The new check finds the query and fragment correctly, including a ? inside a fragment and an opaque IRI such as mailto:a@b?subject=. Lone surrogates and noncharacters are rejected, and supplementary private-use characters (U+100000) are allowed only in the query. Emoji such as http://x/😀 are still valid.

Minor

1. The CHANGELOG doesn't list every new rejection (CHANGELOG.md, the new iri entry)
The entry lists private-use characters outside the query, noncharacters and lone surrogates. containsNonIriCharacter also rejects U+FFF0 to U+FFFD, which includes the U+FFFD replacement character and U+FFFC. It also rejects U+E0000 to U+E0FFF, since neither range is ucschar. U+E0000 to U+E0FFF covers emoji tag sequences, such as the England flag 🏴󠁧󠁢󠁥󠁮󠁧󠁿, and the Variation Selectors Supplement used in CJK names.
Reproduced: http://x/a�b, the England flag emoji http://x/🏴󠁧󠁢󠁥󠁮󠁧󠁿 and http://x/葛󠄀 (U+845B + VS17) are valid as iri and iri-reference at 2de9814f, and invalid on this branch.
Rejecting them is correct under RFC 3987, but users will notice. Please name both ranges in the entry, as the uri-template entry below it already does.

2. No tests for the supplementary-plane boundaries of isUcschar (IriCharacterFormatTest)
Nothing tests the (cp & 0xFFFF) <= 0xFFFD check, the U+E0000 to U+E0FFF exclusion, U+FFF0 to U+FFFD, or the upper end of iprivate. If any of these regressed, the new tests and the vendored suite would still pass. Suggested cases:

  • http://x/� (U+1FFFE): false
  • http://x/󠄀 (U+E0100): false
  • http://x/a�b: false
  • http://x/?� (U+10FFFE in the query): false
  • http://x/😀 (emoji): true

The CHANGELOG names U+FFF0 to U+FFFD and U+E0000 to U+E0FFF. Add test
cases for the supplementary-plane, U+FFF0 and iprivate boundaries.
@ravismash

Copy link
Copy Markdown
Contributor Author

Thanks Steve. Both are in 285940b: the CHANGELOG names both ranges, and IriCharacterFormatTest has your five cases plus the U+FFEF/U+FFF0, U+E0FFF/U+E1000 and U+10FFFD boundaries.

@stevehu

stevehu commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Thanks, both items are fixed at 285940b2. The CHANGELOG entry now names the U+FFF0 to U+FFFD and U+E0000 to U+E0FFF ranges with examples, and I checked each new boundary case in IriCharacterFormatTest by hand. The full test suite passes (11,309 run, 0 failures, 45 skipped), and the changes from the base 2de9814f match the CHANGELOG. This is ready to merge.

Two small things. Neither blocks merging:

1. Unicode space characters that RFC 3987 allows are rejected (already the case at 2de9814f)
http://x/a b, http://x/a
b and http://x/a b are invalid as iri and iri-reference, but U+00A0, U+2028 and U+3000 are all ucschar. matches parses the value with java.net.URI, which refuses any character for which Character.isSpaceChar is true. This PR didn't cause it, but the new AbstractRFC3987Format Javadoc says it allows the non-ASCII characters RFC 3987 allows, so the docs now promise more than the code does.
Suggestion: leave the fix for a follow-up. The likely fix is to percent-encode non-ASCII characters before parsing, while still running the character checks on the raw value, and that changes what validate(URI) and validateIri(URI) receive, so it deserves its own PR and CHANGELOG entry. For this PR, a sentence in the AbstractRFC3987Format Javadoc would be enough, e.g. "Unicode space characters such as U+00A0 and U+3000 are rejected, since java.net.URI cannot parse them." I'll open an issue for the follow-up.

2. Two boundaries are still untested (IriCharacterFormatTest)
The lower end of ucschar U+FDF0 to U+FFEF, and the end of the plane-15 iprivate range in the query. Both behave correctly today. If you're pushing again for item 1 anyway, these four lines would cover them; otherwise it's fine to skip:

"http://x/� | false",
"http://x/ﷰ | true",
"http://x/?󿿽 | true",
"http://x/?� | false",

@stevehu
stevehu merged commit b87ef06 into networknt:master Dec 3, 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.

2 participants