mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
uri: Fix handling of empty ports for uri_parser_rfc3986 (#19645)
* uri: Fix handling of empty ports for uri_parser_rfc3986 * NEWS * uri: Skip the port validation during parsing when port component is empty
This commit is contained in:
2
NEWS
2
NEWS
@@ -66,6 +66,8 @@ PHP NEWS
|
||||
the Uri\WhatWg\Url parser. (timwolla)
|
||||
. Reject out-of-range ports when using the Uri\Rfc3986\Uri parser.
|
||||
(timwolla)
|
||||
. Return null instead of 0 for Uri\Rfc3986\Uri::getPort() when the
|
||||
URI contains an empty port. (timwolla)
|
||||
. Clean up naming of internal API. (timwolla)
|
||||
|
||||
28 Aug 2025, PHP 8.5.0beta2
|
||||
|
||||
31
ext/uri/tests/059.phpt
Normal file
31
ext/uri/tests/059.phpt
Normal file
@@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
Test empty ports become null
|
||||
--EXTENSIONS--
|
||||
uri
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$uri = new \Uri\Rfc3986\Uri('https://example.com:');
|
||||
var_dump($uri, $uri->getPort());
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
object(Uri\Rfc3986\Uri)#%d (8) {
|
||||
["scheme"]=>
|
||||
string(5) "https"
|
||||
["username"]=>
|
||||
NULL
|
||||
["password"]=>
|
||||
NULL
|
||||
["host"]=>
|
||||
string(11) "example.com"
|
||||
["port"]=>
|
||||
NULL
|
||||
["path"]=>
|
||||
string(0) ""
|
||||
["query"]=>
|
||||
NULL
|
||||
["fragment"]=>
|
||||
NULL
|
||||
}
|
||||
NULL
|
||||
@@ -212,7 +212,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_port_read(const
|
||||
{
|
||||
const UriUriA *uriparser_uri = get_uri_for_reading(internal_uri->uri, read_mode);
|
||||
|
||||
if (has_text_range(&uriparser_uri->portText)) {
|
||||
if (has_text_range(&uriparser_uri->portText) && get_text_range_length(&uriparser_uri->portText) > 0) {
|
||||
ZVAL_LONG(retval, port_str_to_zend_long_checked(uriparser_uri->portText.first, get_text_range_length(&uriparser_uri->portText)));
|
||||
} else {
|
||||
ZVAL_NULL(retval);
|
||||
@@ -326,15 +326,14 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str
|
||||
/* Make the resulting URI independent of the 'uri_str'. */
|
||||
uriMakeOwnerMmA(&uri, mm);
|
||||
|
||||
if (
|
||||
has_text_range(&uri.portText)
|
||||
&& port_str_to_zend_long_checked(uri.portText.first, get_text_range_length(&uri.portText)) == -1
|
||||
) {
|
||||
if (!silent) {
|
||||
zend_throw_exception(uri_invalid_uri_exception_ce, "The port is out of range", 0);
|
||||
}
|
||||
if (has_text_range(&uri.portText) && get_text_range_length(&uri.portText) > 0) {
|
||||
if (port_str_to_zend_long_checked(uri.portText.first, get_text_range_length(&uri.portText)) == -1) {
|
||||
if (!silent) {
|
||||
zend_throw_exception(uri_invalid_uri_exception_ce, "The port is out of range", 0);
|
||||
}
|
||||
|
||||
goto fail;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
php_uri_parser_rfc3986_uris *uriparser_uris = uriparser_create_uris();
|
||||
|
||||
Reference in New Issue
Block a user