Unverified Commit c1cc0d5c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2945033 by longwave, yobottehg, TMWagner, vdsh, jlatorre, catch:...

Issue #2945033 by longwave, yobottehg, TMWagner, vdsh, jlatorre, catch: HtmlHeadLink processing does not allow for duplicated alternate hreflang links

(cherry picked from commit 8f497e0a)
parent c051ff75
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -436,7 +436,15 @@ protected function processHtmlHeadLink(array $html_head_link) {
        '#attributes' => $attributes,
      ];
      $href = $attributes['href'];
      $attached['html_head'][] = [$element, 'html_head_link:' . $attributes['rel'] . ':' . $href];
      $rel = $attributes['rel'];

      // Allow multiple hreflang tags to use the same href.
      if (isset($attributes['hreflang'])) {
        $attached['html_head'][] = [$element, 'html_head_link:' . $rel . ':' . $attributes['hreflang'] . ':' . $href];
      }
      else {
        $attached['html_head'][] = [$element, 'html_head_link:' . $rel . ':' . $href];
      }

      if ($should_add_header) {
        // Also add a HTTP header "Link:".
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public function htmlHeaderLink() {
    $render['#attached']['html_head_link'][] = [['href' => '/foo?bar=<baz>&baz=false', 'rel' => 'alternate'], TRUE];
    $render['#attached']['html_head_link'][] = [['href' => '/not-added-to-http-headers', 'rel' => 'alternate'], FALSE];
    $render['#attached']['html_head_link'][] = [['href' => '/foo/bar', 'hreflang' => 'nl', 'rel' => 'alternate'], TRUE];
    $render['#attached']['html_head_link'][] = [['href' => '/foo/bar', 'hreflang' => 'de', 'rel' => 'alternate'], TRUE];
    return $render;
  }

+5 −0
Original line number Diff line number Diff line
@@ -65,8 +65,13 @@ public function testAttachments() {
    $expected_link_headers = [
      '</foo?bar=&lt;baz&gt;&amp;baz=false>; rel="alternate"',
      '</foo/bar>; hreflang="nl"; rel="alternate"',
      '</foo/bar>; hreflang="de"; rel="alternate"',
    ];
    $this->assertEquals($expected_link_headers, $this->getSession()->getResponseHeaders()['Link']);

    // Check that duplicate alternate URLs with different hreflangs are allowed.
    $test_link = $this->xpath('//head/link[@rel="alternate"][@href="/foo/bar"]');
    $this->assertEquals(2, count($test_link), 'Duplicate alternate URLs are allowed.');
  }

  /**