Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7ad285

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

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+5-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+7Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.