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

Commit e195cc6

Browse files
committed
Merge branch 'hotfix/3743' into develop
Close zendframework/zendframework#3743
6 parents f4ac757 + a65cb66 + ecb09fb + 6de3f68 + cb8f354 + 54ca56f commit e195cc6

File tree

2 files changed

+75
-13
lines changed

2 files changed

+75
-13
lines changed

src/Header/AbstractAccept.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function getParametersFromFieldValuePart($fieldValuePart)
168168
$explode = explode('=', $param, 2);
169169

170170
$value = trim($explode[1]);
171-
if ($value[0] == '"' && substr($value, -1) == '"') {
171+
if (isset($value[0]) && $value[0] == '"' && substr($value, -1) == '"') {
172172
$value = substr(substr($value, 1), 0, -1);
173173
}
174174

@@ -341,10 +341,17 @@ protected function matchAcceptParams($match1, $match2)
341341
foreach ($match2->params as $key => $value) {
342342
if (isset($match1->params[$key])) {
343343
if (strpos($value, '-')) {
344-
$values = explode('-', $value, 2);
345-
if ($values[0] > $match1->params[$key] ||
346-
$values[1] < $match1->params[$key])
347-
{
344+
preg_match(
345+
'/^(?|([^"-]*)|"([^"]*)")-(?|([^"-]*)|"([^"]*)")\z/',
346+
$value,
347+
$pieces
348+
);
349+
350+
if (count($pieces) == 3 &&
351+
(version_compare($pieces[1], $match1->params[$key], '<=') xor
352+
version_compare($pieces[2], $match1->params[$key], '>=')
353+
)
354+
) {
348355
return false;
349356
}
350357
} elseif (strpos($value, '|')) {

test/Header/AcceptTest.php

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,59 @@ public function testWildcardWithDifferentParamsAndRanges()
280280
$this->assertEquals('21', $res->getParams()->version);
281281
}
282282

283+
/**
284+
* @group 3739
285+
* @covers Accept::matchAcceptParams()
286+
*/
287+
public function testParamRangesWithDecimals()
288+
{
289+
$acceptHeader = Accept::fromString('Accept: application/vnd.com.example+xml; version=10');
290+
$this->assertFalse($acceptHeader->match('application/vnd.com.example+xml; version="\"3.1\"-\"3.1.1-DEV\""'));
291+
}
292+
293+
/**
294+
* @group 3740
295+
* @dataProvider provideParamRanges
296+
* @covers Accept::matchAcceptParams()
297+
* @covers Accept::getParametersFromFieldValuePart()
298+
*/
299+
public function testParamRangesSupportDevStage($range, $input, $success)
300+
{
301+
$acceptHeader = Accept::fromString(
302+
'Accept: application/vnd.com.example+xml; version="' . addslashes($input) . '"'
303+
);
304+
305+
$res = $acceptHeader->match(
306+
'application/vnd.com.example+xml; version="' . addslashes($range) . '"'
307+
);
308+
309+
if ($success) {
310+
$this->assertInstanceOf('Zend\Http\Header\Accept\FieldValuePart\AcceptFieldValuePart', $res);
311+
} else {
312+
$this->assertFalse($res);
313+
}
314+
}
315+
316+
/**
317+
* @group 3740
318+
* @return array
319+
*/
320+
public function provideParamRanges()
321+
{
322+
return array(
323+
array('"3.1.1-DEV"-3.1.1', '3.1.1', true),
324+
array('3.1.0-"3.1.1-DEV"', '3.1.1', false),
325+
array('3.1.0-"3.1.1-DEV"', '3.1.1-DEV', true),
326+
array('3.1.0-"3.1.1-DEV"', '3.1.2-DEV', false),
327+
array('3.1.0-"3.1.1"', '3.1.2-DEV', false),
328+
array('3.1.0-"3.1.1"', '3.1.0-DEV', false),
329+
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.0', true),
330+
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.1', false),
331+
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.1-BETA', true),
332+
array('"3.1.0-DEV"-"3.1.1-BETA"', '3.1.0-DEV', true),
333+
);
334+
}
335+
283336
public function testVersioningAndPriorization()
284337
{
285338
$acceptStr = 'Accept: text/html; version=23, text/json; version=15.3; q=0.9,' .
@@ -301,14 +354,16 @@ public function testVersioningAndPriorization()
301354
$this->assertEquals($value, $res->$key);
302355
}
303356

304-
$expected = (object) array('typeString' => 'text/html',
305-
'type' => 'text',
306-
'subtype' => 'html',
307-
'subtypeRaw' => 'html',
308-
'format' => 'html',
309-
'priority' => 0.4,
310-
'params' => array('q' => 0.4, 'level' => 2),
311-
'raw' => 'text/html;level=2;q=0.4');
357+
$expected = (object) array(
358+
'typeString' => 'text/html',
359+
'type' => 'text',
360+
'subtype' => 'html',
361+
'subtypeRaw' => 'html',
362+
'format' => 'html',
363+
'priority' => 0.4,
364+
'params' => array('q' => 0.4, 'level' => 2),
365+
'raw' => 'text/html;level=2;q=0.4'
366+
);
312367

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

0 commit comments

Comments
 (0)