Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ PHP 8.6 UPGRADE NOTES
system.

- URI:
. __construct(), parse(), and with*() of Uri\WhatWg\Url, and
Uri\WhatWg\UrlBuilder::build() now report validation errors in the order
in which they are detected. This reverses the order of multiple errors
compared to PHP 8.5.
. Uri\WhatWg\Url::__construct() now sets $softErrors to an empty array when
URL processing throws an exception, instead of preserving its value.
URL validation errors remain available in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var_dump($softErrors);
?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified path is malformed (MissingSchemeNonRelativeUrl)
enum(Uri\WhatWg\UrlValidationErrorType::MissingSchemeNonRelativeUrl)
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
enum(Uri\WhatWg\UrlValidationErrorType::MissingSchemeNonRelativeUrl)
array(0) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Test Uri\WhatWg\UrlBuilder::build() - error - clears soft errors when an excepti
--FILE--
<?php

$referenceErrors = [];

try {
new Uri\WhatWg\Url("ht\ttps://");
} catch (Throwable $e) {
$referenceErrors = $e->errors;
}

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("ht\ttps");
$builder->setHost(null);
Expand All @@ -13,6 +21,10 @@ try {
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
var_dump(
array_map(static fn($error) => $error->type, $e->errors)
=== array_map(static fn($error) => $error->type, $referenceErrors)
);
}

var_dump($softErrors);
Expand Down Expand Up @@ -40,5 +52,6 @@ array(2) {
bool(true)
}
}
bool(true)
array(0) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - success - validation warning order without base URL
Comment thread
kocsismate marked this conversation as resolved.
--FILE--
<?php

$errors = [];
$referenceErrors = [];

$reference = new Uri\WhatWg\Url('https://127.0.0.1.\newPath', null, $referenceErrors);

$url = new Uri\WhatWg\UrlBuilder()
->setScheme('https')
->setHost('127.0.0.1.')
->setPath('\newPath')
->build(null, $errors);

var_dump($url->toAsciiString());
var_dump($url);
var_dump($errors);
var_dump($errors == $referenceErrors);
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));
var_dump($url->equals($reference, Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(25) "https://127.0.0.1/newPath"
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(9) "127.0.0.1"
["port"]=>
NULL
["path"]=>
string(8) "/newPath"
["query"]=>
NULL
["fragment"]=>
NULL
}
array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(0) ""
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::Ipv4EmptyPart)
["failure"]=>
bool(false)
}
[1]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(8) "\newPath"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidReverseSoldius)
["failure"]=>
bool(false)
}
}
bool(true)
bool(true)
bool(true)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ array(3) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(1) " "
string(6) " abc "
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand All @@ -57,7 +57,7 @@ array(3) {
[2]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(6) " abc "
string(1) " "
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(2) " #"
string(3) " #"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand All @@ -49,7 +49,7 @@ array(2) {
[1]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(3) " #"
string(2) " #"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(2) " ?"
string(3) " ?"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand All @@ -49,7 +49,7 @@ array(2) {
[1]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(3) " ?"
string(2) " ?"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var_dump($url->withPath("/zz")->getPath());
string(5) "/c:/x"
array(2) {
[0]=>
string(14) "InvalidUrlUnit"
[1]=>
string(29) "FileInvalidWindowsDriveLetter"
[1]=>
string(14) "InvalidUrlUnit"
}
string(3) "/zz"
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(1) " "
string(21) " https://example.org "
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand All @@ -44,7 +44,7 @@ array(2) {
[1]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(21) " https://example.org "
string(1) " "
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
Expand Down
9 changes: 6 additions & 3 deletions ext/uri/uri_parser_whatwg.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ ZEND_ATTRIBUTE_NONNULL static bool append_validation_error(
ZEND_ATTRIBUTE_NONNULL static const char *fill_errors_inner(HashTable *errors)
{
const char *result = NULL;
lexbor_plog_t *log = lexbor_parser.log;
const size_t length = lexbor_plog_length(log);

lexbor_plog_entry_t *lxb_error;
while ((lxb_error = lexbor_array_obj_pop(&lexbor_parser.log->list)) != NULL) {
for (size_t i = 0; i < length; i++) {
const lexbor_plog_entry_t *lxb_error = lexbor_array_obj_get(&log->list, i);
const char *reason;
if (append_validation_error(errors, lxb_error->id, (const char *) lxb_error->data, &reason)) {
if (append_validation_error(errors, lxb_error->id, (const char *) lxb_error->data, &reason) && result == NULL) {
result = reason;
}
}
lexbor_plog_clean(log);

return result;
}
Expand Down
Loading