Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bff9574

Browse filesBrowse files
bug #33353 Return null as Expire header if it was set to null (danrot)
This PR was squashed before being merged into the 3.4 branch (closes #33353). Discussion ---------- Return null as Expire header if it was set to null | Q | A | ------------- | --- | Branch? | 3.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> This PR fixes a regression introduces in #33332. If you set the `Expires` header to null when creating a `Response`, the `getExpires` function returned a date instead of null. ```php $response = new Response(null, 200, ['Expires' => null]); $response->getExpires(); // Returns a date currently, but should return null ``` See also [the comment](#33332 (comment)) in the PR introducing this regression. Commits ------- 5e3c7ea Return null as Expire header if it was set to null
2 parents 593ec61 + 5e3c7ea commit bff9574
Copy full SHA for bff9574

File tree

3 files changed

+25
-1
lines changed
Filter options

3 files changed

+25
-1
lines changed

‎src/Symfony/Component/HttpFoundation/HeaderBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/HeaderBag.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ public function get($key, $default = null, $first = true)
121121
}
122122

123123
if ($first) {
124-
return \count($headers[$key]) ? (string) $headers[$key][0] : $default;
124+
if (!$headers[$key]) {
125+
return $default;
126+
}
127+
128+
if (null === $headers[$key][0]) {
129+
return null;
130+
}
131+
132+
return (string) $headers[$key][0];
125133
}
126134

127135
return $headers[$key];

‎src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public function testGetDate()
4848
$this->assertInstanceOf('DateTime', $headerDate);
4949
}
5050

51+
public function testGetDateNull()
52+
{
53+
$bag = new HeaderBag(['foo' => null]);
54+
$headerDate = $bag->getDate('foo');
55+
$this->assertNull($headerDate);
56+
}
57+
5158
public function testGetDateException()
5259
{
5360
$this->expectException('RuntimeException');
@@ -96,6 +103,9 @@ public function testGet()
96103
$bag->set('foo', 'bor', false);
97104
$this->assertEquals('bar', $bag->get('foo'), '->get return first value');
98105
$this->assertEquals(['bar', 'bor'], $bag->get('foo', 'nope', false), '->get return all values as array');
106+
107+
$bag->set('baz', null);
108+
$this->assertNull($bag->get('baz', 'nope'), '->get return null although different default value is given');
99109
}
100110

101111
public function testSetAssociativeArray()

‎src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ public function testExpire()
369369
$this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh');
370370
}
371371

372+
public function testNullExpireHeader()
373+
{
374+
$response = new Response(null, 200, ['Expires' => null]);
375+
$this->assertNull($response->getExpires());
376+
}
377+
372378
public function testGetTtl()
373379
{
374380
$response = new Response();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.