Query parameters like _format in URL cause incorrect URL processing

Created on 23 May 2018, over 6 years ago
Updated 15 February 2023, almost 2 years ago

We have an endpoint that specifies ?_format=json since it is a View that needs to be displayed as JSON. See the following: https://www.drupal.org/node/2954953 β†’

It looks like this:

/en-ca/service/locations/area?_format=json

In the latest alpha, the Domain Source module's outbound path processor is assuming too much, or there's a bug. Not sure which.

The error received on this endpoint, instead of returning the correct JSON, shows:

{"message":"No route found for the specified format html."}

Basically the $options['query'] is blank. However if you fill it in, it still causes the error at this line:

$url = Url::fromUserInput($alias, $options);

The quick solution is to do something like this before we grab the URL. I don't know if this is a good one for all cases, but since query params aren't being done correctly in this outbound processor when building the URL it's the only thing I can think that works:

    // The _format query parameter causes issues when building the URL from user
    // input, so just return the path before doing other processing.
    if (is_object($request) && $request->query != NULL) {
      $query_params = $request->query->all();
      if (!empty($query_params) && isset($query_params['_format'])) {
        return $path;
      }
    }
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024