Skip to content
Draft
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
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3418,7 +3418,7 @@ function uniqid(string $prefix = "", bool $more_entropy = false): string {}
* @return int|string|array<string, int|string>|null|false
* @refcount 1
*/
function parse_url(string $url, int $component = -1): int|string|array|null|false {}
function parse_url(string $url, int $component = -1, bool $strict = true): int|string|array|null|false {}

/**
* @compile-time-eval
Expand Down
3 changes: 2 additions & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ext/standard/ftp_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char
char *transport;
int transport_len;

resource = php_url_parse(path);
resource = php_url_parse_ex(path, strlen(path));
if (resource == NULL || resource->path == NULL) {
if (resource && presource) {
*presource = resource;
Expand Down Expand Up @@ -949,8 +949,8 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr
int result;
char tmp_line[512];

resource_from = php_url_parse(url_from);
resource_to = php_url_parse(url_to);
resource_from = php_url_parse_ex(url_from, strlen(url_from));
resource_to = php_url_parse_ex(url_to, strlen(url_to));
/* Must be same scheme (ftp/ftp or ftps/ftps), same host, and same port
(or a 21/0 0/21 combination which is also "same")
Also require paths to/from */
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
return NULL;
}

resource = php_url_parse(path);
resource = php_url_parse_ex(path, strlen(path));
if (resource == NULL) {
return NULL;
}
Expand Down Expand Up @@ -888,7 +888,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,

php_url_free(resource);
/* check for invalid redirection URLs */
if ((resource = php_url_parse(new_path)) == NULL) {
if ((resource = php_url_parse_ex(new_path, strlen(new_path))) == NULL) {
php_stream_wrapper_log_error(wrapper, options, "Invalid redirect URL! %s", new_path);
goto out;
}
Expand Down
8 changes: 6 additions & 2 deletions ext/standard/tests/url/bug55399.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ Bug #55399 (parse_url() incorrectly treats ':' as a valid path)
--FILE--
<?php

var_dump(parse_url(":"));
try {
parse_url(":");
} catch(ValueError $e) {
echo $e->getMessage();
}

?>
--EXPECT--
bool(false)
Invalid path (:)
40 changes: 22 additions & 18 deletions ext/standard/tests/url/parse_url_basic_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ include_once(__DIR__ . '/urls.inc');

foreach ($urls as $url) {
echo "\n--> $url: ";
var_dump(parse_url($url));
try {
var_dump(parse_url($url));
} catch (ValueError $e) {
echo $e->getMessage() . "\n";
}
}

echo "Done";
Expand Down Expand Up @@ -762,7 +766,7 @@ echo "Done";
string(9) "/blah.com"
}

--> x://::abc/?: bool(false)
--> x://::abc/?: Invalid port (abc)

--> http://::?: array(3) {
["scheme"]=>
Expand Down Expand Up @@ -791,9 +795,9 @@ echo "Done";
int(6)
}

--> http://?:/: bool(false)
--> http://?:/: Invalid host (?:/)

--> http://@?:/: bool(false)
--> http://@?:/: Invalid host (?:/)

--> file:///:: array(2) {
["scheme"]=>
Expand Down Expand Up @@ -884,31 +888,31 @@ echo "Done";
string(1) "/"
}

--> http:///blah.com: bool(false)
--> http:///blah.com: Invalid host (/blah.com)

--> http://:80: bool(false)
--> http://:80: Invalid host (:80)

--> http://user@:80: bool(false)
--> http://user@:80: Invalid host (:80)

--> http://user:pass@:80: bool(false)
--> http://user:pass@:80: Invalid host (:80)

--> http://:: bool(false)
--> http://:: Invalid host (:)

--> http://@/: bool(false)
--> http://@/: Invalid host (/)

--> http://@:/: bool(false)
--> http://@:/: Invalid host (:/)

--> http://:/: bool(false)
--> http://:/: Invalid host (:/)

--> http://?: bool(false)
--> http://?: Invalid host (?)

--> http://#: bool(false)
--> http://#: Invalid host (#)

--> http://?:: bool(false)
--> http://?:: Invalid host (?:)

--> http://:?: bool(false)
--> http://:?: Invalid host (:?)

--> http://blah.com:123456: bool(false)
--> http://blah.com:123456: Invalid port (123456)

--> http://blah.com:abcdef: bool(false)
--> http://blah.com:abcdef: Invalid port (abcdef)
Done
40 changes: 22 additions & 18 deletions ext/standard/tests/url/parse_url_basic_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ include_once(__DIR__ . '/urls.inc');

foreach ($urls as $url) {
echo "--> $url : ";
var_dump(parse_url($url, PHP_URL_SCHEME));
try {
var_dump(parse_url($url, PHP_URL_SCHEME));
} catch (ValueError $e) {
echo $e->getMessage() . "\n";
}

}

Expand Down Expand Up @@ -89,12 +93,12 @@ echo "Done";
--> http://x:? : string(4) "http"
--> x:blah.com : string(1) "x"
--> x:/blah.com : string(1) "x"
--> x://::abc/? : bool(false)
--> x://::abc/? : Invalid port (abc)
--> http://::? : string(4) "http"
--> http://::# : string(4) "http"
--> x://::6.5 : string(1) "x"
--> http://?:/ : bool(false)
--> http://@?:/ : bool(false)
--> http://?:/ : Invalid host (?:/)
--> http://@?:/ : Invalid host (?:/)
--> file:///: : string(4) "file"
--> file:///a:/ : string(4) "file"
--> file:///ab:/ : string(4) "file"
Expand All @@ -108,18 +112,18 @@ echo "Done";
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : string(5) "https"
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
--> http://user:pass@:80 : bool(false)
--> http://: : bool(false)
--> http://@/ : bool(false)
--> http://@:/ : bool(false)
--> http://:/ : bool(false)
--> http://? : bool(false)
--> http://# : bool(false)
--> http://?: : bool(false)
--> http://:? : bool(false)
--> http://blah.com:123456 : bool(false)
--> http://blah.com:abcdef : bool(false)
--> http:///blah.com : Invalid host (/blah.com)
--> http://:80 : Invalid host (:80)
--> http://user@:80 : Invalid host (:80)
--> http://user:pass@:80 : Invalid host (:80)
--> http://: : Invalid host (:)
--> http://@/ : Invalid host (/)
--> http://@:/ : Invalid host (:/)
--> http://:/ : Invalid host (:/)
--> http://? : Invalid host (?)
--> http://# : Invalid host (#)
--> http://?: : Invalid host (?:)
--> http://:? : Invalid host (:?)
--> http://blah.com:123456 : Invalid port (123456)
--> http://blah.com:abcdef : Invalid port (abcdef)
Done
40 changes: 22 additions & 18 deletions ext/standard/tests/url/parse_url_basic_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ include_once(__DIR__ . '/urls.inc');

foreach ($urls as $url) {
echo "--> $url : ";
var_dump(parse_url($url, PHP_URL_HOST));
try {
var_dump(parse_url($url, PHP_URL_HOST));
} catch (ValueError $e) {
echo $e->getMessage() . "\n";
}
}

echo "Done";
Expand Down Expand Up @@ -88,12 +92,12 @@ echo "Done";
--> http://x:? : string(1) "x"
--> x:blah.com : NULL
--> x:/blah.com : NULL
--> x://::abc/? : bool(false)
--> x://::abc/? : Invalid port (abc)
--> http://::? : string(1) ":"
--> http://::# : string(1) ":"
--> x://::6.5 : string(1) ":"
--> http://?:/ : bool(false)
--> http://@?:/ : bool(false)
--> http://?:/ : Invalid host (?:/)
--> http://@?:/ : Invalid host (?:/)
--> file:///: : NULL
--> file:///a:/ : NULL
--> file:///ab:/ : NULL
Expand All @@ -107,18 +111,18 @@ echo "Done";
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : string(11) "example.com"
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
--> http://user:pass@:80 : bool(false)
--> http://: : bool(false)
--> http://@/ : bool(false)
--> http://@:/ : bool(false)
--> http://:/ : bool(false)
--> http://? : bool(false)
--> http://# : bool(false)
--> http://?: : bool(false)
--> http://:? : bool(false)
--> http://blah.com:123456 : bool(false)
--> http://blah.com:abcdef : bool(false)
--> http:///blah.com : Invalid host (/blah.com)
--> http://:80 : Invalid host (:80)
--> http://user@:80 : Invalid host (:80)
--> http://user:pass@:80 : Invalid host (:80)
--> http://: : Invalid host (:)
--> http://@/ : Invalid host (/)
--> http://@:/ : Invalid host (:/)
--> http://:/ : Invalid host (:/)
--> http://? : Invalid host (?)
--> http://# : Invalid host (#)
--> http://?: : Invalid host (?:)
--> http://:? : Invalid host (:?)
--> http://blah.com:123456 : Invalid port (123456)
--> http://blah.com:abcdef : Invalid port (abcdef)
Done
40 changes: 22 additions & 18 deletions ext/standard/tests/url/parse_url_basic_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ include_once(__DIR__ . '/urls.inc');

foreach ($urls as $url) {
echo "--> $url : ";
var_dump(parse_url($url, PHP_URL_PORT));
try {
var_dump(parse_url($url, PHP_URL_PORT));
} catch (ValueError $e) {
echo $e->getMessage() . "\n";
}
}

echo "Done";
Expand Down Expand Up @@ -88,12 +92,12 @@ echo "Done";
--> http://x:? : NULL
--> x:blah.com : NULL
--> x:/blah.com : NULL
--> x://::abc/? : bool(false)
--> x://::abc/? : Invalid port (abc)
--> http://::? : NULL
--> http://::# : NULL
--> x://::6.5 : int(6)
--> http://?:/ : bool(false)
--> http://@?:/ : bool(false)
--> http://?:/ : Invalid host (?:/)
--> http://@?:/ : Invalid host (?:/)
--> file:///: : NULL
--> file:///a:/ : NULL
--> file:///ab:/ : NULL
Expand All @@ -107,18 +111,18 @@ echo "Done";
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : int(0)
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
--> http://user:pass@:80 : bool(false)
--> http://: : bool(false)
--> http://@/ : bool(false)
--> http://@:/ : bool(false)
--> http://:/ : bool(false)
--> http://? : bool(false)
--> http://# : bool(false)
--> http://?: : bool(false)
--> http://:? : bool(false)
--> http://blah.com:123456 : bool(false)
--> http://blah.com:abcdef : bool(false)
--> http:///blah.com : Invalid host (/blah.com)
--> http://:80 : Invalid host (:80)
--> http://user@:80 : Invalid host (:80)
--> http://user:pass@:80 : Invalid host (:80)
--> http://: : Invalid host (:)
--> http://@/ : Invalid host (/)
--> http://@:/ : Invalid host (:/)
--> http://:/ : Invalid host (:/)
--> http://? : Invalid host (?)
--> http://# : Invalid host (#)
--> http://?: : Invalid host (?:)
--> http://:? : Invalid host (:?)
--> http://blah.com:123456 : Invalid port (123456)
--> http://blah.com:abcdef : Invalid port (abcdef)
Done
Loading