Skip to content

Commit

Permalink
Fix regexp for finding media type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Jan 31, 2018
1 parent d435e7a commit dfcd047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/JsonApi/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,8 @@ protected function isValidMediaTypeHeader(string $headerName): bool
{
$header = $this->getHeaderLine($headerName);

// The header doesn't contain the media type
if (strpos($header, "application/vnd.api+json") === false) {
return true;
}

// The media type is modified with media type parameters
if (preg_match("/application\/vnd\.api\+json\s*;/i", $header)) {
if (preg_match("/application\/vnd\.api\+json\s*;\s*[a-z0-9]+/i", $header)) {
return false;
}

Expand Down
14 changes: 11 additions & 3 deletions tests/JsonApi/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public function validateJsonApiContentTypeHeader()
$this->assertValidContentTypeHeader("application/vnd.api+json");
}

/**
* @test
*/
public function validateJsonApiContentTypeHeaderWithSemicolon()
{
$this->assertValidContentTypeHeader("application/vnd.api+json;");
}

/**
* @test
*/
Expand Down Expand Up @@ -55,7 +63,7 @@ public function validateMultipleMediaTypeContentTypeHeader()
*/
public function validateCaseInsensitiveContentTypeHeader()
{
$this->assertValidContentTypeHeader("Application/vnd.Api+JSON, text/*;q=0.3, text/html;q=0.7");
$this->assertValidContentTypeHeader("Application/vnd.Api+JSON, text/*;q=0.3, text/html;Q=0.7");
}

/**
Expand All @@ -79,10 +87,10 @@ public function validateInvalidContentTypeHeaderWithWhitespaceBeforeParameter()
/**
* @test
*/
public function validateContentTypeHeaderWithCharsetMediaType()
public function validateInvalidContentTypeHeaderWithCharsetMediaType()
{
$this->expectException(MediaTypeUnsupported::class);
$this->assertInvalidContentTypeHeader("application/vnd.api+json; charset=utf-8");
$this->assertInvalidContentTypeHeader("application/vnd.api+json; Charset=utf-8");
}

private function assertValidContentTypeHeader($value)
Expand Down

0 comments on commit dfcd047

Please sign in to comment.