Response loses URL fragment after adds check logged in to url

Created on 4 May 2022, over 2 years ago
Updated 14 June 2023, over 1 year ago

Problem/Motivation

The commit from the issue Login fails and no warning is issued if cookies are not enabled β†’ alter the response to add the param check_logged_in, but it does due a wrong param it loses part of the URL.

On the method Cookie::addCheckToUrl() the option fragment is considered with hash, but on the UrlHelper is without Hash, so the response loses the fragment.

https://git.drupalcode.org/project/drupal/-/commit/d5ee37a05d0e43a93d280...

  public function addCheckToUrl(ResponseEvent $event) {
    $response = $event->getResponse();
...
        if (!empty($options['#fragment'])) {
          $url .= '#' . $options['#fragment'];
        }
        $response->setTargetUrl($url);

UrHelper::parse()
https://git.drupalcode.org/project/drupal/-/blob/d5ee37a05d0e43a93d28050...

public static function parse($url) {
....
      if (strpos($url, '#') !== FALSE) {
        list($url, $options['fragment']) = explode('#', $url, 2);
      }

Steps to reproduce

In our case we altered the user_login submit to add a redirection to a url with hash.

$url = Url::fromUri('entity:node/' . $node->id() . '#rating', ['query' => ['rate' => 'open']]);
$account = \Drupal::entityTypeManager()->getStorage('user')->load($uid);
user_login_finalize($account);
$form_state->setRedirectUrl($url);

The result is https://domain.com/node/123?rate=open&check_logged_in=1 (without #rating)

Proposed resolution

Patch Cookie method to fix this error

πŸ› Bug report
Status

Closed: duplicate

Version

9.5

Component
Request processingΒ  β†’

Last updated 5 days ago

No maintainer
Created by

πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

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