Fixed: HeaderBag::parseCacheControl() not parsing quoted zero correctly
When having a Cache-Control header like: max-age="0" isset($match[2]) is true but $match[2] containing: "0", it is evaluated as false and 'true' will be set to "max-age" entry instead of "0".
This commit is contained in:
parent
d451933ca1
commit
9e4681963d
@ -317,7 +317,7 @@ class HeaderBag implements \IteratorAggregate, \Countable
|
||||
$cacheControl = array();
|
||||
preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true);
|
||||
$cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
|
||||
}
|
||||
|
||||
return $cacheControl;
|
||||
|
@ -125,6 +125,13 @@ class HeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('max-age=10, public, s-maxage=100', $bag->get('cache-control'));
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveParsingQuotedZero()
|
||||
{
|
||||
$bag = new HeaderBag(array('cache-control' => 'max-age="0"'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
|
||||
$this->assertEquals(0, $bag->getCacheControlDirective('max-age'));
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveOverrideWithReplace()
|
||||
{
|
||||
$bag = new HeaderBag(array('cache-control' => 'private, max-age=100'));
|
||||
|
Reference in New Issue
Block a user