Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - port - leading zeros
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("http://example.com:000000000000000000008080");
Comment thread
TimWolla marked this conversation as resolved.
Resolved

var_dump($uri);
var_dump($uri->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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - port - leading zeros - zero
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("http://example.com:000000000000000000000000");

var_dump($uri);
var_dump($uri->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"
5 changes: 5 additions & 0 deletions ext/uri/uri_parser_rfc3986.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading