Skip to content

Commit f7ad285

Browse files
committed
[Request] Fix support of custom mime types with parameters
1 parent 483da73 commit f7ad285

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
@@ -1238,8 +1238,9 @@ public function getMimeType($format)
12381238
*/
12391239
public function getFormat($mimeType)
12401240
{
1241+
$canonicalMimeType = null;
12411242
if (false !== $pos = strpos($mimeType, ';')) {
1242-
$mimeType = substr($mimeType, 0, $pos);
1243+
$canonicalMimeType = substr($mimeType, 0, $pos);
12431244
}
12441245

12451246
if (null === static::$formats) {
@@ -1250,6 +1251,9 @@ public function getFormat($mimeType)
12501251
if (in_array($mimeType, (array) $mimeTypes)) {
12511252
return $format;
12521253
}
1254+
if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
1255+
return $format;
1256+
}
12531257
}
12541258
}
12551259

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy