When setting the redirect path in hook_user_login(), if I set $form_state['redirect'] as an array with query params

$form_state['redirect'] = array(
  'node/123',
  array(
    'query' => array(
      'foo' => 'foo',
      'bar' => 'bar',
    ),
  ),
);

the array gets run through url twice. First in _ajax_register_execute_form() and the second in ctools_ajax_command_redirect(). When the query parameters are included directly in the path, the full url gets run through drupal_encode_path() which breaks the query path.

http://example.com/node/123%3Ffoo%3Dfoo%26bar%3Dbar
vs
http://example.com/node/123?foo=foo&bar=bar

I believe the attached patch fixes the problem.

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

akkina’s picture

It returned a URL (/ode/123?foo=foo&bar=bar) which was removed a first character n when I applied this patch.
I'm wondering why a first character (leading slash) needs to be removed from a URL.

By the way, I've got another solution, so I'll attach it here.

akkina’s picture

It seems like removing leading slash from a URL is no longer necessary.
Therefore, I'll attach the updated patch.

dmytro-aragorn made their first commit to this issue’s fork.

dmytro-aragorn’s picture

In my case login page has a destination URL param with additional query params. And after the login form submission user was redirected to the non-existing page because query params from destination URL weren't encoded.

It's happen because the destination param is set to the ctools_ajax_command_redirect() function which additionally call url() with where URL and query params are set as a single string.

To fix that need to split the redirect URL and possible URL params abs sent them as individual arguments into ctools_ajax_command_redirect() .