From 9cc7cfaa1cdc86f29cb8b89cf1b6fe9481b8488c Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Mon, 9 Jan 2023 14:19:04 -0600
Subject: [PATCH] Issue #3226334 by albertosilva, pauger, xjm, smustgrave,
 K3vin_nl, krisahil: PathAliasManager could not find the alias by the internal
 path

---
 core/modules/path_alias/src/AliasManager.php             | 2 +-
 .../path_alias/tests/src/Unit/AliasManagerTest.php       | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/core/modules/path_alias/src/AliasManager.php b/core/modules/path_alias/src/AliasManager.php
index 0e2df806792d..9eea31934b60 100644
--- a/core/modules/path_alias/src/AliasManager.php
+++ b/core/modules/path_alias/src/AliasManager.php
@@ -221,7 +221,7 @@ public function getAliasByPath($path, $langcode = NULL) {
       if (!empty($this->preloadedPathLookups[$langcode])) {
         $this->lookupMap[$langcode] = $this->pathAliasRepository->preloadPathAlias($this->preloadedPathLookups[$langcode], $langcode);
         // Keep a record of paths with no alias to avoid querying twice.
-        $this->noAlias[$langcode] = array_flip(array_diff_key($this->preloadedPathLookups[$langcode], array_keys($this->lookupMap[$langcode])));
+        $this->noAlias[$langcode] = array_flip(array_diff($this->preloadedPathLookups[$langcode], array_keys($this->lookupMap[$langcode])));
       }
     }
 
diff --git a/core/modules/path_alias/tests/src/Unit/AliasManagerTest.php b/core/modules/path_alias/tests/src/Unit/AliasManagerTest.php
index 1bff1a5d80ae..a03417c3517c 100644
--- a/core/modules/path_alias/tests/src/Unit/AliasManagerTest.php
+++ b/core/modules/path_alias/tests/src/Unit/AliasManagerTest.php
@@ -259,7 +259,14 @@ public function testGetAliasByPathCachedMatch() {
 
     $language = $this->setUpCurrentLanguage();
 
-    $cached_paths = [$language->getId() => [$path]];
+    // Use a set of cached paths where the tested path is in any position, not
+    // only in the first one.
+    $cached_paths = [
+      $language->getId() => [
+        '/another/path',
+        $path,
+      ],
+    ];
     $this->cache->expects($this->once())
       ->method('get')
       ->with($this->cacheKey)
-- 
GitLab