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

Skip to content

Commit 855cd91

Browse files
committed
[Request] Fix support of custom mime types with parameters
1 parent 2710a88 commit 855cd91

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,22 +1232,25 @@ public function getMimeType($format)
12321232
/**
12331233
* Gets the format associated with the mime type.
12341234
*
1235-
* @param string $mimeType The associated mime type
1235+
* @param string $extendedMimeType The associated mime type
12361236
*
12371237
* @return string|null The format (null if not found)
12381238
*/
1239-
public function getFormat($mimeType)
1239+
public function getFormat($extendedMimeType)
12401240
{
1241-
if (false !== $pos = strpos($mimeType, ';')) {
1242-
$mimeType = substr($mimeType, 0, $pos);
1241+
if (false !== $pos = strpos($extendedMimeType, ';')) {
1242+
$mimeType = substr($extendedMimeType, 0, $pos);
12431243
}
12441244

12451245
if (null === static::$formats) {
12461246
static::initializeFormats();
12471247
}
12481248

12491249
foreach (static::$formats as $format => $mimeTypes) {
1250-
if (in_array($mimeType, (array) $mimeTypes)) {
1250+
if (in_array($extendedMimeType, (array) $mimeTypes)) {
1251+
return $format;
1252+
}
1253+
if (isset($mimeType) && in_array($mimeType, (array) $mimeTypes)) {
12511254
return $format;
12521255
}
12531256
}

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