Skip to content

Commit

Permalink
Merge pull request #31 from axklim/allow_0_value_in_headers
Browse files Browse the repository at this point in the history
Fixed bug with '0' value in the header
  • Loading branch information
sirn-se authored Jan 8, 2024
2 parents 986ae50 + 9fd9de0 commit 82a0166
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Http/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ private function handleHeader(string $name, string|array $value): void
}
$value = is_array($value) ? $value : [$value];
foreach ($value as $content) {
if (!(is_string($content) || is_numeric($content)) || empty($content = trim($content))) {
$content = trim($content);
if ('' === $content) {
throw new InvalidArgumentException("Invalid header value(s) provided.");
}
$this->headers[strtolower($name)][$name][] = $content;
Expand Down
36 changes: 36 additions & 0 deletions tests/suites/http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,40 @@ public function testHaederValueError(): void
$this->expectExceptionMessage("Invalid header value(s) provided.");
$request->withHeader('name', '');
}

/**
* @dataProvider provideInvalidHeaderValues
* @
*/
public function testHeaderValueInvalidVariants($value): void
{
$request = new Request();
$this->expectException(InvalidArgumentException::class);
$request->withHeader('name', $value);
}

public static function provideInvalidHeaderValues(): \Generator
{
yield [''];
yield [' '];
}

/**
* @dataProvider provideValidHeaderValues
* @
*/
public function testHeaderValueValidVariants($value): void
{
$request = new Request();
$request = $request->withHeader('name', $value);
$this->assertInstanceOf(Request::class, $request);
}

public static function provideValidHeaderValues(): \Generator
{
yield ['null'];
yield ['0'];
yield [' 0'];
yield ['1'];
}
}

0 comments on commit 82a0166

Please sign in to comment.