Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/7374-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Mar 27, 2015
2 parents b44104c + 27ee42b commit dea46b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Header/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function fromString($headerLine)
$parameters = array();
foreach ($parts as $parameter) {
$parameter = trim($parameter);
if (!preg_match('/^(?P<key>[^\s\=]+)\=(?P<value>[^\s\=]*)$/', $parameter, $matches)) {
if (!preg_match('/^(?P<key>[^\s\=]+)\="?(?P<value>[^\s\"]*)"?$/', $parameter, $matches)) {
continue;
}
$parameters[$matches['key']] = $matches['value'];
Expand Down
23 changes: 23 additions & 0 deletions test/Header/ContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,27 @@ public function testReturnsMatchingMediaTypeOfFirstCriteriaToValidate($criteria)
$result = $header->match($criteria);
$this->assertEquals('application/vnd.*+json', $result);
}

public function contentTypeParameterExamples()
{
return array(
'no-quotes' => array('Content-Type: foo/bar; param=baz', 'baz'),
'with-quotes' => array('Content-Type: foo/bar; param="baz"', 'baz'),
'with-equals' => array('Content-Type: foo/bar; param=baz=bat', 'baz=bat'),
'with-equals-and-quotes' => array('Content-Type: foo/bar; param="baz=bat"', 'baz=bat'),
);
}

/**
* @dataProvider contentTypeParameterExamples
*/
public function testContentTypeParsesParametersCorrectly($headerString, $expectedParameterValue)
{
$contentTypeHeader = ContentType::fromString($headerString);

$parameters = $contentTypeHeader->getParameters();

$this->assertArrayHasKey('param', $parameters);
$this->assertSame($expectedParameterValue, $parameters['param']);
}
}

0 comments on commit dea46b2

Please sign in to comment.