1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 19:23:22 +02:00
Files
Tim Düsterhus 156c847467 uri: Fix handling of the errors == NULL && !silent for uri_parser_whatwg (#19748)
* uri: Fix handling of the `errors == NULL && !silent` for uri_parser_whatwg

Previously, when `errors` was `NULL`, the `errors` pointer was used to set the
`$errors` property when throwing the exception, leading to a crash. Use a local
zval to pass the errors to the Exception and copy it into the `errors` input
when it is non-`NULL`.

* uri: Only pass the `errors` zval when interested in it in `php_uri_instantiate_uri()`

This is no longer necessary since the previous commit and also is a layering
violation, since `php_uri_instantiate_uri()` should not care how `parse_uri()`
works internally.

* uri: Use `ZVAL_EMPTY_ARRAY()` when no parsing errors are available

* uri: Avoid redundant refcounting in error handling of uri_parser_whatwg

* NEWS
2025-09-09 00:10:39 +02:00

30 lines
588 B
PHP

--TEST--
Test the Lexbor-based URI parser
--EXTENSIONS--
uri
zend_test
--FILE--
<?php
try {
var_dump(zend_test_uri_parser('invalid uri', "Uri\\WhatWg\\Url"));
} catch (\Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage(), PHP_EOL;
var_dump($e->errors);
}
?>
--EXPECTF--
The specified URI is malformed (MissingSchemeNonRelativeUrl)
array(1) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (3) {
["context"]=>
string(11) "invalid uri"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::MissingSchemeNonRelativeUrl)
["failure"]=>
bool(true)
}
}