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

Skip to content

Commit e75d7f0

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

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
@@ -1239,7 +1239,7 @@ public function getMimeType($format)
12391239
public function getFormat($mimeType)
12401240
{
12411241
if (false !== $pos = strpos($mimeType, ';')) {
1242-
$mimeType = substr($mimeType, 0, $pos);
1242+
$canonicalMimeType = substr($mimeType, 0, $pos);
12431243
}
12441244

12451245
if (null === static::$formats) {
@@ -1250,6 +1250,9 @@ public function getFormat($mimeType)
12501250
if (in_array($mimeType, (array) $mimeTypes)) {
12511251
return $format;
12521252
}
1253+
if (isset($canonicalMimeType) && in_array($canonicalMimeType, (array) $mimeTypes)) {
1254+
return $format;
1255+
}
12531256
}
12541257
}
12551258

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)
0