Skip to content
Snippets Groups Projects
Unverified Commit 8f497e0a 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
parent 7578516f
No related branches found
No related tags found
No related merge requests found
...@@ -436,7 +436,15 @@ protected function processHtmlHeadLink(array $html_head_link) { ...@@ -436,7 +436,15 @@ protected function processHtmlHeadLink(array $html_head_link) {
'#attributes' => $attributes, '#attributes' => $attributes,
]; ];
$href = $attributes['href']; $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) { if ($should_add_header) {
// Also add a HTTP header "Link:". // Also add a HTTP header "Link:".
......
...@@ -80,6 +80,7 @@ public function htmlHeaderLink() { ...@@ -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' => '/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' => '/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' => 'nl', 'rel' => 'alternate'], TRUE];
$render['#attached']['html_head_link'][] = [['href' => '/foo/bar', 'hreflang' => 'de', 'rel' => 'alternate'], TRUE];
return $render; return $render;
} }
......
...@@ -65,8 +65,13 @@ public function testAttachments() { ...@@ -65,8 +65,13 @@ public function testAttachments() {
$expected_link_headers = [ $expected_link_headers = [
'</foo?bar=&lt;baz&gt;&amp;baz=false>; rel="alternate"', '</foo?bar=&lt;baz&gt;&amp;baz=false>; rel="alternate"',
'</foo/bar>; hreflang="nl"; rel="alternate"', '</foo/bar>; hreflang="nl"; rel="alternate"',
'</foo/bar>; hreflang="de"; rel="alternate"',
]; ];
$this->assertEquals($expected_link_headers, $this->getSession()->getResponseHeaders()['Link']); $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.');
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment