Skip to content

Fix idn-hostname throwing ValueError on empty string - #178

Merged
sorinsarca merged 2 commits into
opis:masterfrom
kayodeo1:idn-hostname-empty-string
Nov 30, 2026
Merged

sorinsarca merged 2 commits into
opis:masterfrom
kayodeo1:idn-hostname-empty-string

Conversation

@kayodeo1

Copy link
Copy Markdown
Contributor

On PHP 8, validating an empty string against "format": "idn-hostname" throws instead of returning a validation error:

$validator = new Opis\JsonSchema\Validator();
$validator->validate('', (object)['type' => 'string', 'format' => 'idn-hostname']);
// ValueError: idn_to_ascii(): Argument #1 ($domain) must not be empty

On PHP 7 idn_to_ascii('') returned false, but PHP 8 throws a ValueError for an empty domain. The closure built in IriFormats::idn() now returns null for an empty string, which callers already treat as invalid, so idnHostname('') returns false on every supported PHP version. idnEmail() is not affected because its regex requires non-empty parts.

The empty string case is in the current JSON-Schema-Test-Suite (format-idn-hostname.json, "empty string"), which is newer than the copy in tests/official.

Tests: added tests/IdnHostnameTest.php (registered in phpunit.xml). It errors with the ValueError before the change and passes after it. The full phpunit run passes locally on PHP 8.4 (6333 tests).

I used an AI assistant to help prepare this change.

Copilot AI balanced review requested due to automatic review settings November 30, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sorinsarca

Copy link
Copy Markdown
Member

@kayodeo1 please remove the added tests, they are not needed for this change.
Thanks!

@kayodeo1

Copy link
Copy Markdown
Contributor Author

@sorinsarca alright.

@sorinsarca
sorinsarca merged commit c696932 into opis:master Nov 30, 2026
8 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