Skip to content

Commit 19f5aaf

Browse files
author
James Galecki
committed
ensure rawheaders is not whitespace
1 parent 14ee1bd commit 19f5aaf

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Util/Http.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TraderInteractive\Util;
44

55
use Exception;
6+
use InvalidArgumentException;
67

78
/**
89
* Static class with various HTTP related functions.
@@ -47,6 +48,10 @@ final class Http
4748
*/
4849
public static function parseHeaders(string $rawHeaders) : array
4950
{
51+
if (empty($rawHeaders)) {
52+
throw new InvalidArgumentException('$rawHeaders cannot be whitespace');
53+
}
54+
5055
$headers = [];
5156
$rawHeaders = preg_replace("/\r\n[\t ]+/", ' ', trim($rawHeaders));
5257
$fields = explode("\r\n", $rawHeaders);

tests/Util/HttpTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ public function parseHeadersMethodAndUrlSet()
9797
$this->assertSame($expected, $result);
9898
}
9999

100+
/**
101+
* Verifies that the rawHeaders string cannot be whitespace.
102+
*
103+
* @test
104+
* @group unit
105+
* @covers ::parseHeaders
106+
*
107+
* @expectedException \InvalidArgumentException
108+
* @expectedExceptionMessage $rawHeaders cannot be whitespace
109+
*
110+
* @return void
111+
*/
112+
public function parseHeadersWhitespace()
113+
{
114+
Http::parseHeaders('');
115+
}
116+
100117
/**
101118
* @test
102119
* @covers ::buildQueryString

0 commit comments

Comments
 (0)