8000 [Request] Fix support of custom mime types with parameters · symfony/symfony@70d2130 · GitHub
[go: up one dir, main page]

Skip to content

Commit 70d2130

Browse files
committed
[Request] Fix support of custom mime types with parameters
1 parent 1b21647 commit 70d2130

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ public static function getMimeTypes($format)
13471347
public function getFormat($mimeType)
13481348
{
13491349
if (false !== $pos = strpos($mimeType, ';')) {
1350-
$mimeType = substr($mimeType, 0, $pos);
1350+
$canonicalMimeType = substr($mimeType, 0, $pos);
13511351
}
13521352

13531353
if (null === static::$formats) {
@@ -1358,6 +1358,9 @@ public function getFormat($mimeType)
13581358
if (in_array($mimeType, (array) $mimeTypes)) {
13591359
return $format;
13601360
}
1361+
if (isset($canonicalMimeType) && in_array($canonicalMimeType, (array) $mimeTypes)) {
1362+
return $format;
1363+
}
13611364
}
13621365
}
13631366

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,13 @@ public function testGetMimeTypesFromInexistentFormat()
342342
$this->assertEquals(array(), Request::getMimeTypes('foo'));
343343
}
344344

345+
public function testGetFormatWithCustomMimeType()
346+
{
347+
$request = new Request();
348+
$request->setFormat('custom', 'application/vnd.foo.api;myversion=2.3');
349+
$this->assertEquals('custom', $request->getFormat('application/vnd.foo.api;myversion=2.3'));
350+
}
351+
345352
public function getFormatToMimeTypeMapProvider()
346353
{
347354
return array(

0 commit comments

Comments
 (0)
0