🌐 AI搜索 & 代理 主页
Skip to content

[HttpFoundation] Regression in Request::getFormat() where new MIME types were already registered #62226

@longwave

Description

@longwave

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions