Issue #3247935 by mfb: drupal_add_html_head_link(): URL in link HTTP header should not be HTML-encoded

merge-requests/1304/head
mcdruid 2021-11-11 14:28:56 +00:00
parent dede132f8e
commit d563595da8
3 changed files with 9 additions and 1 deletions

View File

@ -2965,7 +2965,7 @@ function drupal_add_html_head_link($attributes, $header = FALSE) {
if ($header) {
// Also add a HTTP header "Link:".
$href = '<' . check_plain($attributes['href']) . '>;';
$href = '<' . $attributes['href'] . '>;';
unset($attributes['href']);
$element['#attached']['drupal_add_http_header'][] = array('Link', $href . drupal_http_header_attributes($attributes), TRUE);
}

View File

@ -3342,12 +3342,15 @@ class DrupalAddHtmlHeadLinkTest extends DrupalWebTestCase {
'</foo?bar=baz>; rel="alternate"',
'</foo/bar>; hreflang="nl"; rel="alternate"',
'</foo/bar>; hreflang="de"; rel="alternate"',
'</foo?bar=baz&baz=false>; hreflang="en"; rel="alternate"',
));
$this->assertEqual($this->drupalGetHeader('Link'), $expected_link_header);
// Check that duplicate alternate URLs with different hreflangs are allowed.
$test_link = $this->xpath('//head/link[@rel="alternate"][@href="/foo/bar"]');
$this->assertEqual(count($test_link), 2, 'Duplicate alternate URLs are allowed.');
// Check that link element attributes are HTML-encoded.
$this->assertRaw('<link href="/foo?bar=baz&amp;baz=false" hreflang="en" rel="alternate" />');
}
}

View File

@ -343,5 +343,10 @@ function common_test_html_head_link() {
'hreflang' => 'de',
'rel' => 'alternate',
), TRUE);
drupal_add_html_head_link(array(
'href' => '/foo?bar=baz&baz=false',
'hreflang' => 'en',
'rel' => 'alternate',
), TRUE);
return '';
}