Skip to content

fix: Reject a trailing newline in idn-hostname - #990

Merged
DannyvdSluijs merged 1 commit into
jsonrainbow:mainfrom
Amoifr:fix-idn-hostname-trailing-newline
Oct 24, 2026
Merged

DannyvdSluijs merged 1 commit into
jsonrainbow:mainfrom
Amoifr:fix-idn-hostname-trailing-newline

Conversation

@Amoifr

@Amoifr Amoifr commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

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, and idn_to_ascii() keeps that newline, so "example.com\n" passed. Using \z fixes it, and the whole suite is green again locally.

The two remaining CurlTest errors on recent runners are fixed separately in #989.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 \z in 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

@DannyvdSluijs
DannyvdSluijs merged commit 20aa2be into jsonrainbow:main Oct 24, 2026
19 checks passed
github-actions Bot added a commit that referenced this pull request Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants