Req #78385 [PATCH]: parse_url() does not include 'query' when question mark is the last char
| From: | israfilov93@gmail.com | Date: | Sat, 11 Jan 2020 15:35:29 +0000 |
| Subject: | Req #78385 [PATCH]: parse_url() does not include 'query' when question mark is the last char | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224844@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78385&edit=1
ID: 78385
Patch added by: israfilov93@gmail.com
Reported by: benjamin dot morel at gmail dot com
Summary: parse_url() does not include 'query' when question
mark is the last char
Status: Open
Type: Feature/Change Request
Package: *URL Functions
Operating System: N/A
PHP Version: 7.3.8
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: ticket-78385 an empty string in parse_url() return when question markâ¦
On GitHub: https://github.com/php/php-src/pull/5078
Patch: https://github.com/php/php-src/pull/5078.patch
Previous Comments:
------------------------------------------------------------------------
[2019-08-07 21:57:12] benjamin dot morel at gmail dot com
Description:
------------
parse_url() returns the same result for these 2 distinct URLs:
http://example.com/foo
http://example.com/foo?
In the first URL, there is no query string, so the 'query' key is not set. This is OK. In
the second URL, there is one, an empty one. As such, PHP should set the 'query' key in the
result array to an empty string. At the moment, it's unset.
The issue with the current implementation is that libraries that parse and build URLs cannot
differentiate these two, and will build a URL that's different from the parsed one.
Another issue is for libraries handling robots.txt files. According to Google (see https://developers.google.com/search/reference/robots_txt),
the following rule:
Disallow: /*.php$
... will match '/filename.php', but not '/filename.php?'.
If I'm using parse_url() to extract the path and query string from the full URL, I will not be
able to differentiate the two URLs above.
Test script:
---------------
var_export(parse_url('http://example.com/foo?'));
echo PHP_EOL, PHP_EOL;
var_export(parse_url('http://example.com/foo?', PHP_URL_QUERY));
Expected result:
----------------
array (
'scheme' => 'http',
'host' => 'example.com',
'path' => '/foo',
'query' => '',
)
''
Actual result:
--------------
array (
'scheme' => 'http',
'host' => 'example.com',
'path' => '/foo',
)
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78385&edit=1