diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index a73cf31..d35457d 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php @@ -58,7 +58,7 @@ public function __construct(AliasManagerInterface $alias_manager, CurrentPathSta public function onKernelController(FilterControllerEvent $event) { // Set the cache key on the alias manager cache decorator. if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { - $this->aliasManager->setCacheKey(trim($this->currentPath->getPath($event->getRequest()), '/')); + $this->aliasManager->setCacheKey(rtrim($this->currentPath->getPath($event->getRequest()), '/')); } } diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index 27c38c3..70d4bd0 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -52,12 +52,12 @@ function testPathCache() { // created. \Drupal::cache('data')->deleteAll(); // Make sure the path is not converted to the alias. - $this->drupalGet($edit['source'], array('alias' => TRUE)); + $this->drupalGet(trim($edit['source'], '/'), array('alias' => TRUE)); $this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['source']), 'Cache entry was created.'); // Visit the alias for the node and confirm a cache entry is created. \Drupal::cache('data')->deleteAll(); - $this->drupalGet($edit['alias']); + $this->drupalGet(trim($edit['alias'], '/')); $this->assertTrue(\Drupal::cache('data')->get('preload-paths:' . $edit['source']), 'Cache entry was created.'); } diff --git a/core/modules/system/src/Tests/Routing/RouteProviderTest.php b/core/modules/system/src/Tests/Routing/RouteProviderTest.php index 06a40fb..44e5102 100644 --- a/core/modules/system/src/Tests/Routing/RouteProviderTest.php +++ b/core/modules/system/src/Tests/Routing/RouteProviderTest.php @@ -430,7 +430,7 @@ public function testRouteCaching() { // A path with a path alias. /** @var \Drupal\Core\Path\AliasStorageInterface $path_storage */ $path_storage = \Drupal::service('path.alias_storage'); - $path_storage->save('path/add/one', 'path/add-one'); + $path_storage->save('/path/add/one', '/path/add-one'); /** @var \Drupal\Core\Path\AliasManagerInterface $alias_manager */ $alias_manager = \Drupal::service('path.alias_manager'); $alias_manager->cacheClear(); diff --git a/core/modules/system/src/Tests/Update/UpdatePathSystemSiteConfigSlashTest.php b/core/modules/system/src/Tests/Update/UpdatePathSystemSiteConfigSlashTest.php index 9c4569f..96b4fa7 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathSystemSiteConfigSlashTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePathSystemSiteConfigSlashTest.php @@ -7,6 +7,6 @@ namespace Drupal\system\Tests\Update; -class UpdatePathSystemSiteConfigSlashTest { +class UpdatePathSystemSiteConfigSlashTest extends UpdatePathTestBase { } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index a0849b1..b33cf96 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1085,3 +1085,45 @@ function system_schema() { return $schema; } + +/** + * Ensures that system.site:site_front, site_403 and site_404 start with a slash. + */ +function system_update_8000() { + /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */ + $config_factory = \Drupal::service('config.factory'); + $config = $config_factory->get('system.site'); + + if (($page_front = $config->get('page.front')) && $page_front[0] !== '/') { + $page_front = '/' . $page_front; + $config->set('page.front', $page_front); + } + + if (($page_403 = $config->get('page.403')) && $page_403[0] !== '/') { + $page_403 = '/' . $page_403; + $config->set('page.403', $page_403); + } + + if (($page_404 = $config->get('page.404')) && $page_404[0] !== '/') { + $page_404 = '/' . $page_404; + $config->set('page.404', $page_404); + } +} + +/** + * Updates {url_alias} to append '/'. + */ +function system_update_8001() { + $query = \Drupal::database()->update('url_alias'); + + if (\Drupal::database()->databaseType() !== 'sqlite') { + $query->expression('source', "concat('/', source)"); + $query->expression('alias', "concat('/', alias)"); + } + else { + $query->expression('source', "source || '/'"); + $query->expression('alias', "alias || '/'"); + } + + $query->execute(); +}