Problem/Motivation

The redirect module has the ability to passthrough querystrings - let's test our implementation and ensure it works for both internal and external redirects and also that the responses are cached correctly.

Doing this reveals a bug. If passthrough query strings are enabled and a redirect is set up to redirect to a URL with a query string then the method

  private function makeRedirectUrl($path, $query) {
    return $query && $this->configFactory->get('redirect.settings')
      ->get('passthrough_querystring')
      ? "{$path}?{$query}"
      : $path;
  }

can result in URLs like xww.example.com/redirect?foo=bar?foo=buz which is not correct at all. This should be doing what the redirect module does and combine the query string parameters properly.

Steps to reproduce

Create a redirect from redirect to node?foo=bar. and ensure passthrough is enabled. Make a request to the decoupled router for redirect?foo=buz and views the resolved URL is broken.

Proposed resolution

Refactor \Drupal\decoupled_router\EventSubscriber\RedirectPathTranslatorSubscriber to be more closely aligned to \Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect and it's code

      // Handle internal path.
      $url = $redirect->getRedirectUrl();
      if ($this->config->get('passthrough_querystring')) {
        $url->setOption('query', (array) $url->getOption('query') + $request_query);
      }

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Category: Task » Bug report
Issue summary: View changes
Status: Active » Needs review
alexpott’s picture

Title: Test redirect.settings:passthrough_querystring for internal and external redirects » Redirects to URLs with query strings and redirect query passthrough enabled is broken
mglaman’s picture

Status: Needs review » Fixed

Looks good! Added to merge train

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • mglaman committed d6b8ea0f on 2.x authored by alexpott
    [#3543594] feat: Redirects to URLs with query strings and redirect query...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.