diff options
author | Islam Israfilov <israfilov93@gmail.com> | 2020-01-11 10:34:05 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-01-13 10:18:23 +0100 |
commit | f553e676ec5605f211a1539667be45fb4b518d2d (patch) | |
tree | 760390a1b7ec45defcded56b79df2e896e672fa7 | |
parent | 4388add2c8897095f34e9be23d86e13db019836c (diff) | |
download | php-git-f553e676ec5605f211a1539667be45fb4b518d2d.tar.gz |
Fixed #78385: Distinguish absent/empty query/fragment
http://example.com/foo => query = null, fragment = null
http://example.com/foo? => query = "", fragment = null
http://example.com/foo# => query = null, fragment = ""
http://example.com/foo?# => query = "", fragment = ""
Closes GH-5078.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | UPGRADING | 8 | ||||
-rw-r--r-- | ext/standard/tests/strings/url_t.phpt | 26 | ||||
-rw-r--r-- | ext/standard/tests/url/parse_url_basic_001.phpt | 38 | ||||
-rw-r--r-- | ext/standard/tests/url/parse_url_basic_008.phpt | 16 | ||||
-rw-r--r-- | ext/standard/tests/url/parse_url_basic_009.phpt | 4 | ||||
-rw-r--r-- | ext/standard/tests/url/parse_url_unterminated.phpt | 38 | ||||
-rw-r--r-- | ext/standard/url.c | 4 |
8 files changed, 102 insertions, 34 deletions
@@ -92,6 +92,8 @@ PHP NEWS (peter279k) . Fixed bug #76859 (stream_get_line skips data if used with data-generating filter). (kkopachev) + . Fixed bug #78385 (parse_url() does not include 'query' when question mark + is the last char). (Islam Israfilov) - tidy: . Removed the unused $use_include_path parameter from tidy_repair_string(). @@ -301,6 +301,14 @@ PHP 8.0 UPGRADE NOTES . FILTER_SANITIZE_MAGIC_QUOTES has been removed. . Calling implode() with parameters in a reverse order ($pieces, $glue) is no longer supported. + . parse_url() will now distinguish absent and empty queries and fragments: + + http://example.com/foo => query = null, fragment = null + http://example.com/foo? => query = "", fragment = null + http://example.com/foo# => query = null, fragment = "" + http://example.com/foo?# => query = "", fragment = "" + + Previously all cases resulted in query and fragment being null. - tidy: . The $use_include_path parameter, which was not used internally, has been diff --git a/ext/standard/tests/strings/url_t.phpt b/ext/standard/tests/strings/url_t.phpt index 79ff3bc4a8..1ff7baff90 100644 --- a/ext/standard/tests/strings/url_t.phpt +++ b/ext/standard/tests/strings/url_t.phpt @@ -213,30 +213,36 @@ $sample_urls = array ( string(10) "/index.php" } ---> www.php.net/?: array(1) { +--> www.php.net/?: array(2) { ["path"]=> string(12) "www.php.net/" + ["query"]=> + string(0) "" } ---> www.php.net:80/?: array(3) { +--> www.php.net:80/?: array(4) { ["host"]=> string(11) "www.php.net" ["port"]=> int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } ---> http://www.php.net/?: array(3) { +--> http://www.php.net/?: array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(11) "www.php.net" ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } ---> http://www.php.net:80/?: array(4) { +--> http://www.php.net:80/?: array(5) { ["scheme"]=> string(4) "http" ["host"]=> @@ -245,6 +251,8 @@ $sample_urls = array ( int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } --> http://www.php.net:80/index.php: array(4) { @@ -359,7 +367,7 @@ $sample_urls = array ( string(10) "/index.php" } ---> http://www.php.net:80/index.php?: array(4) { +--> http://www.php.net:80/index.php?: array(5) { ["scheme"]=> string(4) "http" ["host"]=> @@ -368,6 +376,8 @@ $sample_urls = array ( int(80) ["path"]=> string(10) "/index.php" + ["query"]=> + string(0) "" } --> http://www.php.net:80/#foo: array(5) { @@ -383,7 +393,7 @@ $sample_urls = array ( string(3) "foo" } ---> http://www.php.net:80/?#: array(4) { +--> http://www.php.net:80/?#: array(6) { ["scheme"]=> string(4) "http" ["host"]=> @@ -392,6 +402,10 @@ $sample_urls = array ( int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" + ["fragment"]=> + string(0) "" } --> http://www.php.net:80/?test=1: array(5) { diff --git a/ext/standard/tests/url/parse_url_basic_001.phpt b/ext/standard/tests/url/parse_url_basic_001.phpt index d59f080fbf..3977a3fc2e 100644 --- a/ext/standard/tests/url/parse_url_basic_001.phpt +++ b/ext/standard/tests/url/parse_url_basic_001.phpt @@ -144,30 +144,36 @@ echo "Done"; string(10) "/index.php" } ---> www.php.net/?: array(1) { +--> www.php.net/?: array(2) { ["path"]=> string(12) "www.php.net/" + ["query"]=> + string(0) "" } ---> www.php.net:80/?: array(3) { +--> www.php.net:80/?: array(4) { ["host"]=> string(11) "www.php.net" ["port"]=> int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } ---> http://www.php.net/?: array(3) { +--> http://www.php.net/?: array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(11) "www.php.net" ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } ---> http://www.php.net:80/?: array(4) { +--> http://www.php.net:80/?: array(5) { ["scheme"]=> string(4) "http" ["host"]=> @@ -176,6 +182,8 @@ echo "Done"; int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } --> http://www.php.net:80/index.php: array(4) { @@ -290,7 +298,7 @@ echo "Done"; string(10) "/index.php" } ---> http://www.php.net:80/index.php?: array(4) { +--> http://www.php.net:80/index.php?: array(5) { ["scheme"]=> string(4) "http" ["host"]=> @@ -299,6 +307,8 @@ echo "Done"; int(80) ["path"]=> string(10) "/index.php" + ["query"]=> + string(0) "" } --> http://www.php.net:80/#foo: array(5) { @@ -314,7 +324,7 @@ echo "Done"; string(3) "foo" } ---> http://www.php.net:80/?#: array(4) { +--> http://www.php.net:80/?#: array(6) { ["scheme"]=> string(4) "http" ["host"]=> @@ -323,6 +333,10 @@ echo "Done"; int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" + ["fragment"]=> + string(0) "" } --> http://www.php.net:80/?test=1: array(5) { @@ -731,11 +745,13 @@ echo "Done"; string(4) "/:80" } ---> http://x:?: array(2) { +--> http://x:?: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(1) "x" + ["query"]=> + string(0) "" } --> x:blah.com: array(2) { @@ -754,18 +770,22 @@ echo "Done"; --> x://::abc/?: bool(false) ---> http://::?: array(2) { +--> http://::?: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(1) ":" + ["query"]=> + string(0) "" } ---> http://::#: array(2) { +--> http://::#: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(1) ":" + ["fragment"]=> + string(0) "" } --> x://::6.5: array(3) { diff --git a/ext/standard/tests/url/parse_url_basic_008.phpt b/ext/standard/tests/url/parse_url_basic_008.phpt index 761eb61179..142da3d561 100644 --- a/ext/standard/tests/url/parse_url_basic_008.phpt +++ b/ext/standard/tests/url/parse_url_basic_008.phpt @@ -38,10 +38,10 @@ echo "Done"; --> http://www.php.net:80 : NULL --> http://www.php.net:80/ : NULL --> http://www.php.net/index.php : NULL ---> www.php.net/? : NULL ---> www.php.net:80/? : NULL ---> http://www.php.net/? : NULL ---> http://www.php.net:80/? : NULL +--> www.php.net/? : string(0) "" +--> www.php.net:80/? : string(0) "" +--> http://www.php.net/? : string(0) "" +--> http://www.php.net:80/? : string(0) "" --> http://www.php.net:80/index.php : NULL --> http://www.php.net:80/foo/bar/index.php : NULL --> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL @@ -52,9 +52,9 @@ echo "Done"; --> http://www.php.net:80/this/../a/../deep/directory/ : NULL --> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : NULL --> http://www.php.net:80/index.php : NULL ---> http://www.php.net:80/index.php? : NULL +--> http://www.php.net:80/index.php? : string(0) "" --> http://www.php.net:80/#foo : NULL ---> http://www.php.net:80/?# : NULL +--> http://www.php.net:80/?# : string(0) "" --> http://www.php.net:80/?test=1 : string(6) "test=1" --> http://www.php.net/?test=1& : string(7) "test=1&" --> http://www.php.net:80/?& : string(1) "&" @@ -91,11 +91,11 @@ echo "Done"; --> gg:9130731 : NULL --> http://user:@pass@host/path?argument?value#etc : string(14) "argument?value" --> http://10.10.10.10/:80 : NULL ---> http://x:? : NULL +--> http://x:? : string(0) "" --> x:blah.com : NULL --> x:/blah.com : NULL --> x://::abc/? : bool(false) ---> http://::? : NULL +--> http://::? : string(0) "" --> http://::# : NULL --> x://::6.5 : NULL --> http://?:/ : bool(false) diff --git a/ext/standard/tests/url/parse_url_basic_009.phpt b/ext/standard/tests/url/parse_url_basic_009.phpt index f08787761d..3634046de2 100644 --- a/ext/standard/tests/url/parse_url_basic_009.phpt +++ b/ext/standard/tests/url/parse_url_basic_009.phpt @@ -54,7 +54,7 @@ echo "Done"; --> http://www.php.net:80/index.php : NULL --> http://www.php.net:80/index.php? : NULL --> http://www.php.net:80/#foo : string(3) "foo" ---> http://www.php.net:80/?# : NULL +--> http://www.php.net:80/?# : string(0) "" --> http://www.php.net:80/?test=1 : NULL --> http://www.php.net/?test=1& : NULL --> http://www.php.net:80/?& : NULL @@ -96,7 +96,7 @@ echo "Done"; --> x:/blah.com : NULL --> x://::abc/? : bool(false) --> http://::? : NULL ---> http://::# : NULL +--> http://::# : string(0) "" --> x://::6.5 : NULL --> http://?:/ : bool(false) --> http://@?:/ : bool(false) diff --git a/ext/standard/tests/url/parse_url_unterminated.phpt b/ext/standard/tests/url/parse_url_unterminated.phpt index 94975ee889..7a0cba8ada 100644 --- a/ext/standard/tests/url/parse_url_unterminated.phpt +++ b/ext/standard/tests/url/parse_url_unterminated.phpt @@ -146,30 +146,36 @@ echo "Done"; string(10) "/index.php" } ---> www.php.net/?: array(1) { +--> www.php.net/?: array(2) { ["path"]=> string(12) "www.php.net/" + ["query"]=> + string(0) "" } ---> www.php.net:80/?: array(3) { +--> www.php.net:80/?: array(4) { ["host"]=> string(11) "www.php.net" ["port"]=> int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } ---> http://www.php.net/?: array(3) { +--> http://www.php.net/?: array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(11) "www.php.net" ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } ---> http://www.php.net:80/?: array(4) { +--> http://www.php.net:80/?: array(5) { ["scheme"]=> string(4) "http" ["host"]=> @@ -178,6 +184,8 @@ echo "Done"; int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" } --> http://www.php.net:80/index.php: array(4) { @@ -292,7 +300,7 @@ echo "Done"; string(10) "/index.php" } ---> http://www.php.net:80/index.php?: array(4) { +--> http://www.php.net:80/index.php?: array(5) { ["scheme"]=> string(4) "http" ["host"]=> @@ -301,6 +309,8 @@ echo "Done"; int(80) ["path"]=> string(10) "/index.php" + ["query"]=> + string(0) "" } --> http://www.php.net:80/#foo: array(5) { @@ -316,7 +326,7 @@ echo "Done"; string(3) "foo" } ---> http://www.php.net:80/?#: array(4) { +--> http://www.php.net:80/?#: array(6) { ["scheme"]=> string(4) "http" ["host"]=> @@ -325,6 +335,10 @@ echo "Done"; int(80) ["path"]=> string(1) "/" + ["query"]=> + string(0) "" + ["fragment"]=> + string(0) "" } --> http://www.php.net:80/?test=1: array(5) { @@ -733,11 +747,13 @@ echo "Done"; string(4) "/:80" } ---> http://x:?: array(2) { +--> http://x:?: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(1) "x" + ["query"]=> + string(0) "" } --> x:blah.com: array(2) { @@ -756,18 +772,22 @@ echo "Done"; --> x://::abc/?: bool(false) ---> http://::?: array(2) { +--> http://::?: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(1) ":" + ["query"]=> + string(0) "" } ---> http://::#: array(2) { +--> http://::#: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(1) ":" + ["fragment"]=> + string(0) "" } --> x://::6.5: array(3) { diff --git a/ext/standard/url.c b/ext/standard/url.c index c2d9340e1c..c73818f08e 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -291,6 +291,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (p < e) { ret->fragment = zend_string_init(p, (e - p), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment)); + } else { + ret->fragment = ZSTR_EMPTY_ALLOC(); } e = p-1; } @@ -301,6 +303,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (p < e) { ret->query = zend_string_init(p, (e - p), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query)); + } else { + ret->query = ZSTR_EMPTY_ALLOC(); } e = p-1; } |