Skip to content

Commit 6fa6381

Browse files
authored
[12.x] Fix Request::getAcceptableContentTypes() changes in Symfony 7.4 (#57783)
* [12.x] Fix `Request::getAcceptableContentTypes()` changes in Symfony 7.4 Symfony 7.4 changes the return value of `getAcceptableContentType()` to include additional value after `;`. E,g: `application/json; charset=utf-8` returns `application/json` in 7.3 and below while 7.4 return the full value. Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 41496fd commit 6fa6381

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Illuminate/Http/Concerns/InteractsWithContentTypes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public function accepts($contentTypes)
5555
$types = (array) $contentTypes;
5656

5757
foreach ($accepts as $accept) {
58+
if ($accept && $pos = strpos($accept, ';')) {
59+
$accept = trim(substr($accept, 0, $pos));
60+
}
61+
5862
if ($accept === '*/*' || $accept === '*') {
5963
return true;
6064
}
@@ -86,6 +90,10 @@ public function prefers($contentTypes)
8690
$contentTypes = (array) $contentTypes;
8791

8892
foreach ($accepts as $accept) {
93+
if ($accept && $pos = strpos($accept, ';')) {
94+
$accept = trim(substr($accept, 0, $pos));
95+
}
96+
8997
if (in_array($accept, ['*/*', '*'])) {
9098
return $contentTypes[0];
9199
}

0 commit comments

Comments
 (0)