Skip to content

Commit b0a1702

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

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,22 +1232,24 @@ 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+
} elseif (isset($mimeType) && in_array($mimeType, (array) $mimeTypes)) {
12511253
return $format;
12521254
}
12531255
}

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