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 3a5b25c

Browse filesBrowse files
priyadinicolas-grekas
authored andcommitted
[HttpFoundation] Request without content-type or content-length header should result in null values, not empty strings
1 parent 77f39fe commit 3a5b25c
Copy full SHA for 3a5b25c

File tree

Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/ServerBag.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getHeaders()
3131
foreach ($this->parameters as $key => $value) {
3232
if (str_starts_with($key, 'HTTP_')) {
3333
$headers[substr($key, 5)] = $value;
34-
} elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true)) {
34+
} elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true) && '' !== $value) {
3535
$headers[$key] = $value;
3636
}
3737
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/ServerBagTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,20 @@ public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
177177
'PHP_AUTH_PW' => '',
178178
], $bag->getHeaders());
179179
}
180+
181+
/**
182+
* An HTTP request without content-type and content-length will result in
183+
* the variables $_SERVER['CONTENT_TYPE'] and $_SERVER['CONTENT_LENGTH']
184+
* containing an empty string in PHP.
185+
*/
186+
public function testRequestWithoutContentTypeAndContentLength()
187+
{
188+
$bag = new ServerBag([
189+
'CONTENT_TYPE' => '',
190+
'CONTENT_LENGTH' => '',
191+
'HTTP_USER_AGENT' => 'foo',
192+
]);
193+
194+
$this->assertSame(['USER_AGENT' => 'foo'], $bag->getHeaders());
195+
}
180196
}

0 commit comments

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