Skip to content

Commit 5dad378

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: [CI] Fix package-tests workflow checks for contracts do not call preg_match() on null
2 parents f07daa1 + 641240f commit 5dad378

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
@@ -1515,7 +1515,7 @@ public function isMethodCacheable()
15151515
public function getProtocolVersion()
15161516
{
15171517
if ($this->isFromTrustedProxy()) {
1518-
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via'), $matches);
1518+
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via') ?? '', $matches);
15191519

15201520
if ($matches) {
15211521
return 'HTTP/'.$matches[2];

Tests/RequestTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,17 +2256,22 @@ public function testProtocolVersion($serverProtocol, $trustedProxy, $via, $expec
22562256
$request = new Request();
22572257
$request->server->set('SERVER_PROTOCOL', $serverProtocol);
22582258
$request->server->set('REMOTE_ADDR', '1.1.1.1');
2259-
$request->headers->set('Via', $via);
2259+
2260+
if (null !== $via) {
2261+
$request->headers->set('Via', $via);
2262+
}
22602263

22612264
$this->assertSame($expected, $request->getProtocolVersion());
22622265
}
22632266

22642267
public function protocolVersionProvider()
22652268
{
22662269
return [
2267-
'untrusted without via' => ['HTTP/2.0', false, '', 'HTTP/2.0'],
2270+
'untrusted with empty via' => ['HTTP/2.0', false, '', 'HTTP/2.0'],
2271+
'untrusted without via' => ['HTTP/2.0', false, null, 'HTTP/2.0'],
22682272
'untrusted with via' => ['HTTP/2.0', false, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/2.0'],
2269-
'trusted without via' => ['HTTP/2.0', true, '', 'HTTP/2.0'],
2273+
'trusted with empty via' => ['HTTP/2.0', true, '', 'HTTP/2.0'],
2274+
'trusted without via' => ['HTTP/2.0', true, null, 'HTTP/2.0'],
22702275
'trusted with via' => ['HTTP/2.0', true, '1.0 fred, 1.1 nowhere.com (Apache/1.1)', 'HTTP/1.0'],
22712276
'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'],
22722277
'trusted with broken via' => ['HTTP/2.0', true, 'HTTP/1^0 foo', 'HTTP/2.0'],

0 commit comments

Comments
 (0)