diff --git a/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php index 7e4d009..7dd55bf 100644 --- a/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php @@ -28,14 +28,11 @@ public function getContext($header = NULL) { $headers = $this->requestStack->getCurrentRequest()->headers->all(); // Order headers by name to have less cache variations. ksort($headers); - $result = NULL; + $result = ''; foreach ($headers as $name => $value) { if ($result) { $result .= '&'; } - else { - $result = ''; - } $result .= $name . '=' . implode(',', $value); } return $result; @@ -47,7 +44,7 @@ public function getContext($header = NULL) { } return '?valueless?'; } - return NULL; + return ''; } /** diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php index 53c108d..b70f187 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php @@ -34,15 +34,15 @@ public function testGetContext($headers, $header_name, $context) { */ public function providerTestGetContext() { return [ - [[], NULL, NULL], - [[], 'foo', NULL], + [[], NULL, ''], + [[], 'foo', ''], // Non-empty headers. [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], NULL, 'alpaca=&llama=rocks&panda=drools&z=0'], [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'llama', 'rocks'], [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'alpaca', '?valueless?'], [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'panda', 'drools'], [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'z', '0'], - [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', NULL], + [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', ''], // Header value could be an array. [['z' => ['0', '1']], NULL, 'z=0,1'], [['z' => ['0', '1'], 'a' => []], NULL, 'a=&z=0,1'],