Skip to content

Commit 0b32baf

Browse files
committed
Fix #80114: parse_url does not accept URLs with port 0
URIs with a 0 port are generally valid, so `parse_url()` should recognize such URIs, but still report the port as missing.
1 parent efdbc36 commit 0b32baf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/standard/tests/url/bug80114.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #80114 (parse_url does not accept URLs with port 0)
3+
--FILE--
4+
<?php
5+
var_dump(parse_url('https://example.com:0/'));
6+
?>
7+
--EXPECT--
8+
array(3) {
9+
["scheme"]=>
10+
string(5) "https"
11+
["host"]=>
12+
string(11) "example.com"
13+
["path"]=>
14+
string(1) "/"
15+
}

ext/standard/url.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
261261
memcpy(port_buf, p, (e - p));
262262
port_buf[e - p] = '\0';
263263
port = ZEND_STRTOL(port_buf, NULL, 10);
264-
if (port > 0 && port <= 65535) {
264+
if ((port > 0 && port <= 65535) || (port == 0 && *port_buf == '0' && e - p == 1)) {
265265
ret->port = (unsigned short)port;
266266
} else {
267267
php_url_free(ret);

0 commit comments

Comments
 (0)