Repository navigation
fix: Reject a trailing newline in idn-hostname - #990
Merged
DannyvdSluijs merged 1 commit intoOct 24, 2026
Merged
Conversation
The LDH check after idn_to_ascii() used `$`, which also matches before a final newline, and idn_to_ascii() keeps that newline. So "example.com\n" was a valid idn-hostname in Draft-07 and 2019-09. Anchor the pattern with `\z` instead.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Both narrowly scoped regex changes correctly reject trailing newlines while preserving valid label matching.
No open issues 🎉
What changed in this PR
Fixes idn-hostname validation in Draft-07 and Draft 2019-09 to reject trailing newlines, matching the newly added upstream JSON Schema Test Suite case.
Changes:
- Replaces
$with\zin both post-IDNA label checks, requiring matches to reach the absolute end of the string.
| File | Description |
|---|---|
| src/JsonSchema/Constraints/Drafts/Draft2019/FormatConstraint.php | Rejects trailing newlines in Draft 2019-09 hostname labels. |
| src/JsonSchema/Constraints/Drafts/Draft07/FormatConstraint.php | Applies the same correction to Draft-07 hostname labels. |
Review effort: Balanced
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.
The JSON Schema Test Suite added an "idn-hostname: trailing newline is invalid" case on Oct 21 (json-schema-org/JSON-Schema-Test-Suite#1226), and since the suite is pulled as
dev-main, every new CI run now fails on it (Draft-07 and 2019-09).The cause is the LDH check after
idn_to_ascii():$also matches before a final newline, andidn_to_ascii()keeps that newline, so"example.com\n"passed. Using\zfixes it, and the whole suite is green again locally.The two remaining
CurlTesterrors on recent runners are fixed separately in #989.