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 NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ PHP NEWS
. Fixed bug GH-19765 (object_properties_load() bypasses readonly property
checks). (timwolla)

- URI:
. Fixed bug GH-19780 (InvalidUrlException should check $errors argument).
(nielsdos)

11 Sep 2025, PHP 8.5.0beta3

- Core:
Expand Down
26 changes: 26 additions & 0 deletions ext/uri/php_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,27 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, uri_str, base_url_object, is_constructor, is_constructor, NULL);
}

static bool is_list_of_whatwg_validation_errors(const HashTable *array)
{
if (!zend_array_is_list(array)) {
return false;
}

ZEND_HASH_FOREACH_VAL(array, zval *val) {
/* Do not allow references as they may change types after checking. */

if (Z_TYPE_P(val) != IS_OBJECT) {
return false;
}

if (!instanceof_function(Z_OBJCE_P(val), uri_whatwg_url_validation_error_ce)) {
return false;
}
} ZEND_HASH_FOREACH_END();

return true;
}

PHP_METHOD(Uri_Rfc3986_Uri, parse)
{
create_rfc3986_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
Expand Down Expand Up @@ -425,6 +446,11 @@ PHP_METHOD(Uri_WhatWg_InvalidUrlException, __construct)
ZVAL_EMPTY_ARRAY(&tmp);
zend_update_property(uri_whatwg_invalid_url_exception_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), &tmp);
} else {
if (!is_list_of_whatwg_validation_errors(Z_ARR_P(errors))) {
zend_argument_value_error(2, "must be a list of %s", ZSTR_VAL(uri_whatwg_url_validation_error_ce->name));
RETURN_THROWS();
}

zend_update_property(uri_whatwg_invalid_url_exception_ce, Z_OBJ_P(ZEND_THIS), ZEND_STRL("errors"), errors);
}
if (EG(exception)) {
Expand Down
29 changes: 29 additions & 0 deletions ext/uri/tests/gh19780.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-19780 (InvalidUrlException should check $errors argument)
--EXTENSIONS--
uri
--FILE--
<?php

use Uri\WhatWg\InvalidUrlException;
use Uri\WhatWg\UrlValidationError;
use Uri\WhatWg\UrlValidationErrorType;

try {
new InvalidUrlException('message', ['foo']);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
new InvalidUrlException('message', [
1 => new UrlValidationError('context', UrlValidationErrorType::HostMissing, true)
]);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError
Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError
Loading