[php-src] Issue #22629: ext/uri: WHATWG Validation error incorrect with empty host and non-empty userinfo
[email protected] (JKingweb) Tue, 7 Jul 2026 14:52:29 +0000
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/22629
Author: JKingweb
### Description
The following code:
```php
<?php
try {
new Uri\WhatWg\Url("https://user:pass@");
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
}
Uri\WhatWg\Url::parse("https://user:pass@", null, $e);
var_dump($e);
```
Resulted in this output:
```
Uri\WhatWg\InvalidUrlException: The specified URI is malformed
array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#6 (3) {
["context"]=>
string(0) ""
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidCredentials)
["failure"]=>
bool(false)
}
[1]=>
object(Uri\WhatWg\UrlValidationError)#7 (3) {
["context"]=>
string(1) "@"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidCredentials)
["failure"]=>
bool(false)
}
}
```
But I expected this output instead:
```
Uri\WhatWg\InvalidUrlException: The specified URI is malformed (HostMissing)
array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#6 (3) {
["context"]=>
string(0) ""
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::HostMissing)
["failure"]=>
bool(true)
}
[1]=>
object(Uri\WhatWg\UrlValidationError)#7 (3) {
["context"]=>
string(1) "@"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidCredentials)
["failure"]=>
bool(false)
}
}
```
The URL specification specifies the following fatal validation error type in step 2.2.1 of the authority state:
> If atSignSeen is true and buffer is the empty string, [host-missing](https://url.spec.whatwg.org/#host-missing) [validation error](https://url.spec.whatwg.org/#validation-error), return failure.
This is tested by the (incorrect) PHP test [whatwg/parsing/host_error_empty2.phpt](https://github.com/php/php-src/blob/4afc970827a038e380551cc97e9a14493cae0854/ext/uri/tests/whatwg/parsing/host_error_empty2.phpt).
### PHP Version
```plain
PHP 8.5.8 (cli) (built: Jul 1 2026 16:35:50) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.8, Copyright (c) Zend Technologies
with Zend OPcache v8.5.8, Copyright (c), by Zend Technologies
```
### Operating System
Arch Linux