Skip to content

ext/uri: WHATWG Validation error incorrect with empty host and non-empty userinfo #22629

Closed

Description

@JKingweb

Description

The following code:

<?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 validation error, return failure.

This is tested by the (incorrect) PHP test whatwg/parsing/host_error_empty2.phpt.

PHP Version

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

Activity

  1. kocsismate commented on Jul 9, 2026

    @kocsismate
    Member

    Thank you very much for the report! I think I identified the bug in the lexbor library. See lexbor/lexbor#393 for details.

  2. added a commit that references this issue on Jul 11, 2026
    8e3ec77
  3. added a commit that references this issue on Jul 12, 2026
    2014eb2
  4. added a commit that references this issue on Jul 12, 2026
    1bf4be9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions