Skip to content

Commit 641240f

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: do not call preg_match() on null
2 parents 937e913 + 090976c commit 641240f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ public function isMethodCacheable()
15071507
public function getProtocolVersion()
15081508
{
15091509
if ($this->isFromTrustedProxy()) {
1510-
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via'), $matches);
1510+
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via') ?? '', $matches);
15111511

15121512
if ($matches) {
15131513
return 'HTTP/'.$matches[2];

Tests/RequestTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,17 +2248,22 @@ public function testProtocolVersion($serverProtocol, $trustedProxy, $via, $expec
22482248
$request = new Request();
22492249
$request->server->set('SERVER_PROTOCOL', $serverProtocol);
22502250
$request->server->set('REMOTE_ADDR', '1.1.1.1');
2251-
$request->headers->set('Via', $via);
2251+
2252+
if (null !== $via) {
2253+
$request->headers->set('Via', $via);
2254+
}
22522255

22532256
$this->assertSame($expected, $request->getProtocolVersion());
22542257
}
22552258

22562259
public function protocolVersionProvider()
22572260
{
22582261
return [
2259-
'untrusted without via' => ['HTTP/2.0', false, '', 'HTTP/2.0'],
2262+
'untrusted with empty via' => ['HTTP/2.0', false, '', 'HTTP/2.0'],
2263+
'untrusted without via' => ['HTTP/2.0', false, null, 'HTTP/2.0'],
22602264
'untrusted with via' => ['HTTP/2.0', false, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/2.0'],
2261-
'trusted without via' => ['HTTP/2.0', true, '', 'HTTP/2.0'],
2265+
'trusted with empty via' => ['HTTP/2.0', true, '', 'HTTP/2.0'],
2266+
'trusted without via' => ['HTTP/2.0', true, null, 'HTTP/2.0'],
22622267
'trusted with via' => ['HTTP/2.0', true, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'],
22632268
'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'],
22642269
'trusted with broken via' => ['HTTP/2.0', true, 'HTTP/1^0 foo', 'HTTP/2.0'],

0 commit comments

Comments
 (0)