Skip to content

Commit 932211d

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [Request] Fix support of custom mime types with parameters
2 parents db869e2 + 09cc0b2 commit 932211d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,9 @@ public function getMimeType($format)
13371337
*/
13381338
public function getFormat($mimeType)
13391339
{
1340+
$canonicalMimeType = null;
13401341
if (false !== $pos = strpos($mimeType, ';')) {
1341-
$mimeType = substr($mimeType, 0, $pos);
1342+
$canonicalMimeType = substr($mimeType, 0, $pos);
13421343
}
13431344

13441345
if (null === static::$formats) {
@@ -1349,6 +1350,9 @@ public function getFormat($mimeType)
13491350
if (in_array($mimeType, (array) $mimeTypes)) {
13501351
return $format;
13511352
}
1353+
if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
1354+
return $format;
1355+
}
13521356
}
13531357
}
13541358

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ public function testGetMimeTypeFromFormat($format, $mimeTypes)
325325
}
326326
}
327327

328+
public function testGetFormatWithCustomMimeType()
329+
{
330+
$request = new Request();
331+
$request->setFormat('custom', 'application/vnd.foo.api;myversion=2.3');
332+
$this->assertEquals('custom', $request->getFormat('application/vnd.foo.api;myversion=2.3'));
333+
}
334+
328335
public function getFormatToMimeTypeMapProvider()
329336
{
330337
return array(

0 commit comments

Comments
 (0)