diff --git a/ext/uri/tests/058.phpt b/ext/uri/tests/058.phpt new file mode 100644 index 000000000000..3d7cef10dff1 --- /dev/null +++ b/ext/uri/tests/058.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test empty ports become null +--EXTENSIONS-- +uri +--FILE-- +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 diff --git a/ext/uri/uri_parser_rfc3986.c b/ext/uri/uri_parser_rfc3986.c index cf7235b071b4..60a183e157e5 100644 --- a/ext/uri/uri_parser_rfc3986.c +++ b/ext/uri/uri_parser_rfc3986.c @@ -205,7 +205,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, str_to_int(uriparser_uri->portText.first, get_text_range_length(&uriparser_uri->portText))); } else { ZVAL_NULL(retval);