Skip to content

Commit 5c41900

Browse files
committed
uri: Fix handling of empty ports for uri_parser_rfc3986
1 parent 1ac91f5 commit 5c41900

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ext/uri/tests/059.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Test empty ports become null
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$uri = new \Uri\Rfc3986\Uri('https://example.com:');
9+
var_dump($uri, $uri->getPort());
10+
11+
?>
12+
--EXPECTF--
13+
object(Uri\Rfc3986\Uri)#%d (8) {
14+
["scheme"]=>
15+
string(5) "https"
16+
["username"]=>
17+
NULL
18+
["password"]=>
19+
NULL
20+
["host"]=>
21+
string(11) "example.com"
22+
["port"]=>
23+
NULL
24+
["path"]=>
25+
string(0) ""
26+
["query"]=>
27+
NULL
28+
["fragment"]=>
29+
NULL
30+
}
31+
NULL

ext/uri/uri_parser_rfc3986.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_port_read(const
212212
{
213213
const UriUriA *uriparser_uri = get_uri_for_reading(internal_uri->uri, read_mode);
214214

215-
if (has_text_range(&uriparser_uri->portText)) {
215+
if (has_text_range(&uriparser_uri->portText) && get_text_range_length(&uriparser_uri->portText) > 0) {
216216
ZVAL_LONG(retval, port_str_to_zend_long_checked(uriparser_uri->portText.first, get_text_range_length(&uriparser_uri->portText)));
217217
} else {
218218
ZVAL_NULL(retval);

0 commit comments

Comments
 (0)