Issue #3245895 by mfb, rcodina, longwave, alexpott: Link HTTP header should not be HTML-encoded

merge-requests/3006/merge
Alex Pott 2023-03-20 09:16:19 +00:00
parent 9dc6f60e72
commit a2ea938fae
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 6 additions and 4 deletions

View File

@ -10,7 +10,6 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\EnforcedResponseException; use Drupal\Core\Form\EnforcedResponseException;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Component\Utility\Html;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
/** /**
@ -420,7 +419,10 @@ class HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorIn
* @param array $html_head_link * @param array $html_head_link
* The 'html_head_link' value of a render array. Each head link is specified * The 'html_head_link' value of a render array. Each head link is specified
* by a two-element array: * by a two-element array:
* - An array specifying the attributes of the link. * - An array specifying the attributes of the link. The 'href' and 'rel'
* attributes are required, and the 'href' attribute is expected to be a
* percent-encoded URI for proper serialization in the Link: HTTP header,
* as specified by RFC 8288.
* - A boolean specifying whether the link should also be a Link: HTTP * - A boolean specifying whether the link should also be a Link: HTTP
* header. * header.
* *
@ -455,7 +457,7 @@ class HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorIn
if ($should_add_header) { if ($should_add_header) {
// Also add a HTTP header "Link:". // Also add a HTTP header "Link:".
$href = '<' . Html::escape($attributes['href']) . '>'; $href = '<' . $attributes['href'] . '>';
unset($attributes['href']); unset($attributes['href']);
if ($param = static::formatHttpHeaderAttributes($attributes)) { if ($param = static::formatHttpHeaderAttributes($attributes)) {
$href .= ';' . $param; $href .= ';' . $param;

View File

@ -63,7 +63,7 @@ class HtmlResponseAttachmentsTest extends BrowserTestBase {
// Test ['#attached']['html_head_link'] when outputted as HTTP header. // Test ['#attached']['html_head_link'] when outputted as HTTP header.
$this->drupalGet('/render_attached_test/html_header_link'); $this->drupalGet('/render_attached_test/html_header_link');
$expected_link_headers = [ $expected_link_headers = [
'</foo?bar=&lt;baz&gt;&amp;baz=false>; rel="alternate"', '</foo?bar=<baz>&baz=false>; rel="alternate"',
'</foo/bar>; hreflang="nl"; rel="alternate"', '</foo/bar>; hreflang="nl"; rel="alternate"',
'</foo/bar>; hreflang="de"; rel="alternate"', '</foo/bar>; hreflang="de"; rel="alternate"',
]; ];