Commit fbb8a06f authored by catch's avatar catch

Issue #2909349 by claudiu.cristea, Wim Leers: UrlHelper::parse() is wrong with...

Issue #2909349 by claudiu.cristea, Wim Leers: UrlHelper::parse() is wrong with absolute URLs having fragment but not query
parent 5c310806
...@@ -148,6 +148,11 @@ public static function parse($url) { ...@@ -148,6 +148,11 @@ public static function parse($url) {
$scheme_delimiter_position = strpos($url, '://'); $scheme_delimiter_position = strpos($url, '://');
$query_delimiter_position = strpos($url, '?'); $query_delimiter_position = strpos($url, '?');
if ($scheme_delimiter_position !== FALSE && ($query_delimiter_position === FALSE || $scheme_delimiter_position < $query_delimiter_position)) { if ($scheme_delimiter_position !== FALSE && ($query_delimiter_position === FALSE || $scheme_delimiter_position < $query_delimiter_position)) {
// Split off the fragment, if any.
if (strpos($url, '#') !== FALSE) {
list($url, $options['fragment']) = explode('#', $url, 2);
}
// Split off everything before the query string into 'path'. // Split off everything before the query string into 'path'.
$parts = explode('?', $url); $parts = explode('?', $url);
...@@ -158,12 +163,7 @@ public static function parse($url) { ...@@ -158,12 +163,7 @@ public static function parse($url) {
} }
// If there is a query string, transform it into keyed query parameters. // If there is a query string, transform it into keyed query parameters.
if (isset($parts[1])) { if (isset($parts[1])) {
$query_parts = explode('#', $parts[1]); parse_str($parts[1], $options['query']);
parse_str($query_parts[0], $options['query']);
// Take over the fragment, if there is any.
if (isset($query_parts[1])) {
$options['fragment'] = $query_parts[1];
}
} }
} }
// Internal URLs. // Internal URLs.
......
...@@ -269,6 +269,14 @@ public static function providerTestParse() { ...@@ -269,6 +269,14 @@ public static function providerTestParse() {
'fragment' => 'footer', 'fragment' => 'footer',
], ],
], ],
'absolute fragment, no query' => [
'http://www.example.com/my/path#footer',
[
'path' => 'http://www.example.com/my/path',
'query' => [],
'fragment' => 'footer',
],
],
[ [
'http://', 'http://',
[ [
...@@ -295,6 +303,14 @@ public static function providerTestParse() { ...@@ -295,6 +303,14 @@ public static function providerTestParse() {
'fragment' => 'footer', 'fragment' => 'footer',
], ],
], ],
'relative fragment, no query' => [
'/my/path#footer',
[
'path' => '/my/path',
'query' => [],
'fragment' => 'footer',
],
],
]; ];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment