-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Description
Symfony version(s) affected
7.4.0-BETA1
Description
Drupal registers the MIME type application/vnd.api+json as format api_json.
#61267 also added application/vnd.api+json as format jsonapi.
After upgrading to Symfony 7.4 this causes routing failures where we specified routes that respond to the api_json format.
How to reproduce
Symfony 7.3:
> $request = Symfony\Component\HttpFoundation\Request::create('/');
> $request->setFormat('api_json', 'application/vnd.api+json');
> $request->getFormat('application/vnd.api+json');
= "api_json"
Symfony 7.4:
> $request = Symfony\Component\HttpFoundation\Request::create('/');
> $request->setFormat('api_json', 'application/vnd.api+json');
> $request->getFormat('application/vnd.api+json');
= "jsonapi"
Possible Solution
A workaround for this is to explicitly deregister the jsonapi format, but we shouldn't need to do this:
> $request = Symfony\Component\HttpFoundation\Request::create('/');
> $request->setFormat('api_json', 'application/vnd.api+json');
> $request->setFormat('jsonapi', []);
> $request->getFormat('application/vnd.api+json');
= "api_json"
Maybe Request::getFormat() should start looking from the newest entries first?
- foreach (static::$formats as $format => $mimeTypes) {
+ foreach (array_reverse(static::$formats) as $format => $mimeTypes) {
or similarly setFormat() could prepend to static::$formats instead of appending?
Additional Context
No response