Problem/Motivation

Since #3496369: Multiple load path aliases without the preload cache the Redirect module tests have been failing. Specifically \Drupal\Tests\redirect\Functional\GlobalRedirectTest::testRedirects when it asserts that 'Test-node' will be redirected to 'test-node'

Steps to reproduce

Run the test

Proposed resolution

The problem was caused by the removal of the AliasManager cache and how the static cache works on \Drupal\path_alias\AliasManager::getPathByAlias(). In head this does:

    // Look for path in storage.
    if ($path_alias = $this->pathAliasRepository->lookupByAlias($alias, $langcode)) {
      $this->lookupMap[$langcode][$path_alias['path']] = $alias;
      return $path_alias['path'];
    }

which results in the node/1 path having the alias Test-node in the redirect test. It should be

    // Look for path in storage.
    if ($path_alias = $this->pathAliasRepository->lookupByAlias($alias, $langcode)) {
      $this->lookupMap[$langcode][$path_alias['path']] = $path_alias['alias'];
      return $path_alias['path'];
    }

which would result in node/1 path having the correct alias test-node.

Remaining tasks

Fix alias manager to store the correct alias and add missing test coverage to core.

User interface changes

None

Introduced terminology

N/a

API changes

None

Data model changes

None

Release notes snippet

N/a

Issue fork drupal-3567086

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

Status: Active » Needs review

This is going to be fun...

    // Look for the alias within the cached map.
    if (isset($this->lookupMap[$langcode]) && ($path = array_search($alias, $this->lookupMap[$langcode]))) {
      return $path;
    }

is case sensitive... so this change would mean that the lookupMap is not going to be a good cache if the alias case is different from the case in the URL. ugh.

berdir’s picture

Not sure I get the full picture yet, but does performance really matter? This is very unlikely to happen much in practice, maybe if you manage to create an alias with uppercase characters and then fix it.

If you have redirect, it will then redirect away, and I wouldn't expect that getPathByAlias() is called that often for the same alias.

Based on debugging this a bit, the initial lookup is even part of the router cache, it's then only called for parents and so on for the breadcrumb and they're all unique calls from what I see with my example on umami.

leaving at needs review for now, not sure if we want a more explicit test for this to assert what's used for the return value, could copy testGetPathByAliasMatch() and simulate that. Probably don't want to test the static cache as we know that won't work.

alexpott’s picture

Title: Removal of Path Alias » Alias case sensitivity after the removal of the preload cache
Status: Needs review » Active
alexpott’s picture

Status: Active » Needs review

I agree I think @berdir you are right this fix is fine for the issue found by the redirect tests. However while testing this out I've discovered another issue - \Drupal\path_alias\AliasPrefixList is case sensitive and it should not be. This means when you make a request for nOde/1 and have an alias for node/1 it does not behave as it should. Going to open a separate issue.

Will try an devise a test for this change that would fail on HEAD without the redirect module in play.

john.oltman’s picture

I noticed this yesterday while testing an 11.2 to 11.3 upgrade. Thank you @alexpott and @berdir for your work on this, the MR fixes the redirect issue.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Contributed project blocker

Looks good to me, did run the test locally and verified it fails. Tagging since this is required to fix redirect tests on 11.3.

  • catch committed ab20bac8 on 11.3.x
    fix: #3567086 Alias case sensitivity after the removal of the preload...
catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main, 11.x and 11.3.x, thanks!

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

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

Maintainers, credit people who helped resolve this issue.

  • catch committed 3f48764a on 11.x
    fix: #3567086 Alias case sensitivity after the removal of the preload...

  • catch committed c14b75dd on main
    fix: #3567086 Alias case sensitivity after the removal of the preload...

Status: Fixed » Closed (fixed)

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