diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index b5ae05f..fd0cd87 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -247,7 +247,7 @@ function testNodeAlias() { $this->drupalGet($edit['path[0][alias]']); $this->assertText($node1->label(), 'Alias works.'); $this->assertResponse(200); - $this->assertIdentical($this->getDrupalSettings()['path']['currentPath'], substr($edit['path[0][alias]'], 1)); + $this->assertIdentical($this->getDrupalSettings()['path']['currentPathUrlAlias'], substr($edit['path[0][alias]'], 1)); // Confirm the 'canonical' and 'shortlink' URLs. $elements = $this->xpath("//link[contains(@rel, 'canonical') and contains(@href, '" . $edit['path[0][alias]'] . "')]"); @@ -313,7 +313,7 @@ function testNodeAlias() { $this->drupalGet(trim($edit['path[0][alias]'], '/')); $this->assertText($node3->label(), 'Alias became relative.'); $this->assertResponse(200); - $this->assertIdentical($this->getDrupalSettings()['path']['currentPath'], substr($edit['path[0][alias]'], 1)); + $this->assertIdentical($this->getDrupalSettings()['path']['currentPathUrlAlias'], substr($edit['path[0][alias]'], 1)); // Create fourth test node. $node4 = $this->drupalCreateNode(); @@ -326,7 +326,7 @@ function testNodeAlias() { $this->drupalGet(trim($edit['path[0][alias]'], '/')); $this->assertText($node4->label(), 'Alias trimmed trailing slash.'); $this->assertResponse(200); - $this->assertIdentical($this->getDrupalSettings()['path']['currentPath'], trim(substr($edit['path[0][alias]'], 1), '/')); + $this->assertIdentical($this->getDrupalSettings()['path']['currentPathUrlAlias'], trim(substr($edit['path[0][alias]'], 1), '/')); } /** diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 9671afe..c1609e6 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -690,15 +690,22 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) { if ($route_match instanceof StackedRouteMatchInterface) { $route_match = $route_match->getMasterRouteMatch(); } - $current_path = $route_match->getRouteName() ? substr($request->getPathInfo(), 1) : ''; - if ($pathPrefix && strpos($current_path, $pathPrefix) === 0) { - $current_path = substr_replace($current_path, '', 0, strlen($pathPrefix)); + $current_path = $route_match->getRouteName() ? Url::fromRouteMatch($route_match)->getInternalPath() : ''; + if (!empty($current_path)) { + $current_path_url_alias = substr($request->getPathInfo(), 1); + if ($pathPrefix && strpos($current_path_url_alias, $pathPrefix) === 0) { + $current_path_url_alias = substr_replace($current_path_url_alias, '', 0, strlen($pathPrefix)); + } + } + else { + $current_path_url_alias = ''; } $current_path_is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route_match->getRouteObject()); $path_settings = [ 'baseUrl' => $request->getBaseUrl() . '/', 'pathPrefix' => $pathPrefix, 'currentPath' => $current_path, + 'currentPathUrlAlias' => $current_path_url_alias, 'currentPathIsAdmin' => $current_path_is_admin, 'isFront' => \Drupal::service('path.matcher')->isFrontPage(), 'currentLanguage' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(),