Req #78385 [NEW]: parse_url() does not include 'query' when question mark is the last char
| From: | benjamin dot morel at gmail dot com | Date: | Wed, 07 Aug 2019 21:57:12 +0000 |
| Subject: | Req #78385 [NEW]: parse_url() does not include 'query' when question mark is the last char | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222129@lists.php.net to get a copy of this message | ||
From: benjamin dot morel at gmail dot com
Operating system: N/A
PHP version: 7.3.8
Package: *URL Functions
Bug Type: Feature/Change Request
Bug description:parse_url() does not include 'query' when question mark is the last char
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 bug report at https://bugs.php.net/bug.php?id=78385&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78385&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78385&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78385&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78385&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78385&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78385&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78385&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78385&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78385&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78385&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78385&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78385&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78385&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78385&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78385&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78385&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78385&r=mysqlcfg