Skip to content
Snippets Groups Projects
Commit 201192be authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

Merge branch '3512574-url-as-fragment' into '11.x'

Bug #3512574: URL un fragment

See merge request !11455
parents bfc9d63d 8fa99bb1
No related branches found
No related tags found
No related merge requests found
Pipeline #473508 failed
Pipeline: drupal

#473511

    Pipeline: drupal

    #473509

      ...@@ -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);
      ......
      ...@@ -386,6 +386,30 @@ public static function providerTestParse() { ...@@ -386,6 +386,30 @@ public static function providerTestParse() {
      'fragment' => 'footer', 'fragment' => 'footer',
      ], ],
      ], ],
      'Absolute URL with URL as fragment' => [
      'http://example.com/my/path#http://example.com',
      [
      'fragment' => 'http://example.com',
      'path' => 'http://example.com/my/path',
      'query' => [],
      ],
      ],
      'Relative URL with URL as fragment' => [
      '/my/path#http://example.com',
      [
      'fragment' => 'http://example.com',
      'path' => '/my/path',
      'query' => [],
      ],
      ],
      'URL as fragment' => [
      '#http://example.com',
      [
      'fragment' => 'http://example.com',
      'path' => '',
      'query' => [],
      ],
      ],
      ]; ];
      } }
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Please register or to comment