Skip to content
Snippets Groups Projects

Bug #3512574: URL un fragment

Open Claudiu Cristea requested to merge issue/drupal-3512574:3512574-url-as-fragment into 11.x
Files
2
@@ -187,13 +187,18 @@ public static function parse($url) {
@@ -187,13 +187,18 @@ public static function parse($url) {
];
];
// External URLs: not using parse_url() here, so we do not have to rebuild
// External URLs: not using parse_url() here, so we do not have to rebuild
// the scheme, host, and path without having any use for it.
// the scheme, host, and path without having any use for it. The URL is
// The URL is considered external if it contains the '://' delimiter. Since
// considered external if it contains the '://' delimiter. Since a URL can
// a URL can also be passed as a query argument, we check if this delimiter
// also be passed as a query or fragment argument, check if this delimiter
// appears in front of the '?' query argument delimiter.
// appears in front of the '?' and '#' query/fragment argument delimiters.
$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)) {
$fragment_delimiter_position = strpos($url, '#');
 
if (
 
$scheme_delimiter_position !== FALSE &&
 
($query_delimiter_position === FALSE || $scheme_delimiter_position < $query_delimiter_position) &&
 
($fragment_delimiter_position === FALSE || $scheme_delimiter_position < $fragment_delimiter_position)
 
) {
// Split off the fragment, if any.
// Split off the fragment, if any.
if (str_contains($url, '#')) {
if (str_contains($url, '#')) {
[$url, $options['fragment']] = explode('#', $url, 2);
[$url, $options['fragment']] = explode('#', $url, 2);
Loading