Skip to content

Commit

Permalink
Fix TypeError in case of empty string a Content-Type (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpatoio authored May 18, 2020
1 parent e3a546f commit 2091dd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PSR7/Validators/BodyValidator/BodyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function messageContentType(MessageInterface $message) : ?string
// ContentType can contain multiple statements (type/subtype + parameters), ie: 'multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__'
// OpenAPI Spec only defines the first part of the header value (type/subtype)
// Other parameters SHOULD be skipped
$contentType = strtok($contentType, ';');
$contentType = (string) strtok($contentType, ';');

return $contentType;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/PSR7/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public function testItValidatesBodyHasUnexpectedTypeRed() : void
$validator->validate($request);
}

public function testItValidatesBodyHasEmptyTypeRed() : void
{
$addr = new OperationAddress('/request-body', 'post');
$request = $this->makeGoodRequest($addr->path(), $addr->method())
->withHeader('Content-Type', '');

$this->expectException(InvalidHeaders::class);
$this->expectExceptionMessage(
'Missing required header "Content-Type" for Request [post /request-body]'
);

$validator = (new ValidatorBuilder())->fromYamlFile($this->apiSpecFile)->getRequestValidator();
$validator->validate($request);
}

public function testItValidatesMessageWrongHeaderValueRed() : void
{
$addr = new OperationAddress('/path1', 'get');
Expand Down

0 comments on commit 2091dd6

Please sign in to comment.