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/3743' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Feb 11, 2013
6 parents f4ac757 + a65cb66 + ecb09fb + 6de3f68 + cb8f354 + 54ca56f commit e195cc6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 13 deletions.
17 changes: 12 additions & 5 deletions src/Header/AbstractAccept.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function getParametersFromFieldValuePart($fieldValuePart)
$explode = explode('=', $param, 2);

$value = trim($explode[1]);
if ($value[0] == '"' && substr($value, -1) == '"') {
if (isset($value[0]) && $value[0] == '"' && substr($value, -1) == '"') {
$value = substr(substr($value, 1), 0, -1);
}

Expand Down Expand Up @@ -341,10 +341,17 @@ protected function matchAcceptParams($match1, $match2)
foreach ($match2->params as $key => $value) {
if (isset($match1->params[$key])) {
if (strpos($value, '-')) {
$values = explode('-', $value, 2);
if ($values[0] > $match1->params[$key] ||
$values[1] < $match1->params[$key])
{
preg_match(
'/^(?|([^"-]*)|"([^"]*)")-(?|([^"-]*)|"([^"]*)")\z/',
$value,
$pieces
);

if (count($pieces) == 3 &&
(version_compare($pieces[1], $match1->params[$key], '<=') xor
version_compare($pieces[2], $match1->params[$key], '>=')
)
) {
return false;
}
} elseif (strpos($value, '|')) {
Expand Down
71 changes: 63 additions & 8 deletions test/Header/AcceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,59 @@ public function testWildcardWithDifferentParamsAndRanges()
$this->assertEquals('21', $res->getParams()->version);
}

/**
* @group 3739
* @covers Accept::matchAcceptParams()
*/
public function testParamRangesWithDecimals()
{
$acceptHeader = Accept::fromString('Accept: application/vnd.com.example+xml; version=10');
$this->assertFalse($acceptHeader->match('application/vnd.com.example+xml; version="\"3.1\"-\"3.1.1-DEV\""'));
}

/**
* @group 3740
* @dataProvider provideParamRanges
* @covers Accept::matchAcceptParams()
* @covers Accept::getParametersFromFieldValuePart()
*/
public function testParamRangesSupportDevStage($range, $input, $success)
{
$acceptHeader = Accept::fromString(
'Accept: application/vnd.com.example+xml; version="' . addslashes($input) . '"'
);

$res = $acceptHeader->match(
'application/vnd.com.example+xml; version="' . addslashes($range) . '"'
);

if ($success) {
$this->assertInstanceOf('Zend\Http\Header\Accept\FieldValuePart\AcceptFieldValuePart', $res);
} else {
$this->assertFalse($res);
}
}

/**
* @group 3740
* @return array
*/
public function provideParamRanges()
{
return array(
array('"3.1.1-DEV"-3.1.1', '3.1.1', true),
array('3.1.0-"3.1.1-DEV"', '3.1.1', false),
array('3.1.0-"3.1.1-DEV"', '3.1.1-DEV', true),
array('3.1.0-"3.1.1-DEV"', '3.1.2-DEV', false),
array('3.1.0-"3.1.1"', '3.1.2-DEV', false),
array('3.1.0-"3.1.1"', '3.1.0-DEV', false),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.0', true),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.1', false),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.1-BETA', true),
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.0-DEV', true),
);
}

public function testVersioningAndPriorization()
{
$acceptStr = 'Accept: text/html; version=23, text/json; version=15.3; q=0.9,' .
Expand All @@ -301,14 +354,16 @@ public function testVersioningAndPriorization()
$this->assertEquals($value, $res->$key);
}

$expected = (object) array('typeString' => 'text/html',
'type' => 'text',
'subtype' => 'html',
'subtypeRaw' => 'html',
'format' => 'html',
'priority' => 0.4,
'params' => array('q' => 0.4, 'level' => 2),
'raw' => 'text/html;level=2;q=0.4');
$expected = (object) array(
'typeString' => 'text/html',
'type' => 'text',
'subtype' => 'html',
'subtypeRaw' => 'html',
'format' => 'html',
'priority' => 0.4,
'params' => array('q' => 0.4, 'level' => 2),
'raw' => 'text/html;level=2;q=0.4'
);

$str = 'text/html; version=17,text/json; version=15-16; q=0.5';
$res = $acceptHeader->match($str);
Expand Down

0 comments on commit e195cc6

Please sign in to comment.