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 677ca9c

Browse filesBrowse files
committed
bug #44502 [HttpFoundation] do not call preg_match() on null (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] do not call preg_match() on null | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44498 | License | MIT | Doc PR | Commits ------- 47298dc do not call preg_match() on null
2 parents 53a45b2 + 47298dc commit 677ca9c
Copy full SHA for 677ca9c

File tree

Expand file treeCollapse file tree

2 files changed

+9
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ public function isMethodCacheable()
15021502
public function getProtocolVersion()
15031503
{
15041504
if ($this->isFromTrustedProxy()) {
1505-
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via'), $matches);
1505+
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via') ?? '', $matches);
15061506

15071507
if ($matches) {
15081508
return 'HTTP/'.$matches[2];

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,17 +2230,22 @@ public function testProtocolVersion($serverProtocol, $trustedProxy, $via, $expec
22302230
$request = new Request();
22312231
$request->server->set('SERVER_PROTOCOL', $serverProtocol);
22322232
$request->server->set('REMOTE_ADDR', '1.1.1.1');
2233-
$request->headers->set('Via', $via);
2233+
2234+
if (null !== $via) {
2235+
$request->headers->set('Via', $via);
2236+
}
22342237

22352238
$this->assertSame($expected, $request->getProtocolVersion());
22362239
}
22372240

22382241
public function protocolVersionProvider()
22392242
{
22402243
return [
2241-
'untrusted without via' => ['HTTP/2.0', false, '', 'HTTP/2.0'],
2244+
'untrusted with empty via' => ['HTTP/2.0', false, '', 'HTTP/2.0'],
2245+
'untrusted without via' => ['HTTP/2.0', false, null, 'HTTP/2.0'],
22422246
'untrusted with via' => ['HTTP/2.0', false, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/2.0'],
2243-
'trusted without via' => ['HTTP/2.0', true, '', 'HTTP/2.0'],
2247+
'trusted with empty via' => ['HTTP/2.0', true, '', 'HTTP/2.0'],
2248+
'trusted without via' => ['HTTP/2.0', true, null, 'HTTP/2.0'],
22442249
'trusted with via' => ['HTTP/2.0', true, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'],
22452250
'trusted with via and protocol name' => ['HTTP/2.0', true, 'HTTP/1.0 fred, HTTP/1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'],
22462251
'trusted with broken via' => ['HTTP/2.0', true, 'HTTP/1^0 foo', 'HTTP/2.0'],

0 commit comments

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