diff --git a/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt new file mode 100644 index 000000000000..e3578fdc56ca --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - port - leading zeros +--FILE-- +toRawString()); +var_dump($uri->toString()); + +?> +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(4) "http" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(8080) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL +} +string(43) "http://example.com:000000000000000000008080" +string(23) "http://example.com:8080" diff --git a/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt new file mode 100644 index 000000000000..75796ddb9c65 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - port - leading zeros - zero +--FILE-- +toRawString()); +var_dump($uri->toString()); + +?> +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(4) "http" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(0) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL +} +string(43) "http://example.com:000000000000000000000000" +string(20) "http://example.com:0" diff --git a/ext/uri/uri_parser_rfc3986.c b/ext/uri/uri_parser_rfc3986.c index d56d053aae58..7fd2102b28a3 100644 --- a/ext/uri/uri_parser_rfc3986.c +++ b/ext/uri/uri_parser_rfc3986.c @@ -334,6 +334,11 @@ static zend_result php_uri_parser_rfc3986_host_write(void *uri, zval *value, zva ZEND_ATTRIBUTE_NONNULL static zend_long port_str_to_zend_long_checked(const char *str, size_t len) { + while (len > 1 && *str == '0') { + str++; + len--; + } + if (len > MAX_LENGTH_OF_LONG) { return -1; }