Req #78385 [Opn->Csd]: parse_url() does not include 'query' when question mark is the last char
| From: | nikic@php.net | Date: | Mon, 13 Jan 2020 09:18:35 +0000 |
| Subject: | Req #78385 [Opn->Csd]: 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-224873@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
Updated by: nikic@php.net
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
+Status: Closed
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:
Automatic comment on behalf of israfilov93@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f553e676ec5605f211a1539667be45fb4b518d2d
Log: Fixed #78385: Distinguish absent/empty query/fragment
Previous Comments:
------------------------------------------------------------------------
[2020-01-11 15:35:29] israfilov93 at gmail dot com
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
------------------------------------------------------------------------
[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