[HttpFoundation] fixed Request::getFormat() when the mime-type has some optional parameter (closes #1235)

This commit is contained in:
Fabien Potencier 2011-06-08 11:12:57 +02:00
parent f16e206cd7
commit 0af4743583
2 changed files with 13 additions and 0 deletions

View File

@ -674,6 +674,10 @@ class Request
*/
public function getFormat($mimeType)
{
if (false !== $pos = strpos($mimeType, ';')) {
$mimeType = substr($mimeType, 0, $pos);
}
if (null === static::$formats) {
static::initializeFormats();
}

View File

@ -146,6 +146,15 @@ class RequestTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @covers Symfony\Component\HttpFoundation\Request::getFormat
*/
public function testGetFormatFromMimeTypeWithParameters()
{
$request = new Request();
$this->assertEquals('json', $request->getFormat('application/json; charset=utf-8'));
}
/**
* @covers Symfony\Component\HttpFoundation\Request::getMimeType
* @dataProvider getFormatToMimeTypeMapProvider