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 70d2130

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

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+11
-1
lines changed

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

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

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
@@ -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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.