diff --git a/core/lib/Drupal/Core/Path/AliasStorageInterface.php b/core/lib/Drupal/Core/Path/AliasStorageInterface.php index 23a7619..ae79300 100644 --- a/core/lib/Drupal/Core/Path/AliasStorageInterface.php +++ b/core/lib/Drupal/Core/Path/AliasStorageInterface.php @@ -29,8 +29,8 @@ * @return array|false * FALSE if the path could not be saved or an associative array containing * the following keys: - * - source (string): The internal system path. - * - alias (string): The URL alias. + * - source (string): The internal system path with a starting slash. + * - alias (string): The URL alias with a starting slash. * - pid (int): Unique path alias identifier. * - langcode (string): The language code of the alias. * - original: For updates, an array with source, alias and langcode with @@ -50,8 +50,8 @@ public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NO * @return array|false * FALSE if no alias was found or an associative array containing the * following keys: - * - source (string): The internal system path. - * - alias (string): The URL alias. + * - source (string): The internal system path with a starting lash. + * - alias (string): The URL alias with a starting slash. * - pid (int): Unique path alias identifier. * - langcode (string): The language code of the alias. */ diff --git a/core/lib/Drupal/Core/Path/PathMatcher.php b/core/lib/Drupal/Core/Path/PathMatcher.php index 10a3899..1f7b88c 100644 --- a/core/lib/Drupal/Core/Path/PathMatcher.php +++ b/core/lib/Drupal/Core/Path/PathMatcher.php @@ -73,7 +73,7 @@ public function matchPath($path, $patterns) { // Convert path settings to a regular expression. $to_replace = array( // Replace newlines with a logical 'or'. - '/\/(\r\n?|\n)/', + '/(\r\n?|\n)/', // Quote asterisks. '/\\\\\*/', // Quote keyword. diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php index 5be2387..024babf 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php @@ -50,7 +50,7 @@ public function processInbound($path, Request $request) { */ public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL) { // The special path '' links to the default front page. - if ($path == '') { + if ($path == '/') { $path = '/'; } return $path; diff --git a/core/modules/language/src/Tests/LanguageSwitchingTest.php b/core/modules/language/src/Tests/LanguageSwitchingTest.php index cc6068a..c9ff8d0 100644 --- a/core/modules/language/src/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php @@ -37,7 +37,7 @@ protected function setUp() { /** * Functional tests for the language switcher block. */ - function ptestLanguageBlock() { + function testLanguageBlock() { // Add language. $edit = array( 'predefined_langcode' => 'fr', @@ -163,7 +163,7 @@ protected function doTestLanguageBlockAnonymous($block_label) { /** * Test language switcher links for domain based negotiation. */ - function ptestLanguageBlockWithDomain() { + function testLanguageBlockWithDomain() { // Add the Italian language. ConfigurableLanguage::createFromLangcode('it')->save(); @@ -225,7 +225,7 @@ function ptestLanguageBlockWithDomain() { /** * Test active class on links when switching languages. */ - function ptestLanguageLinkActiveClass() { + function testLanguageLinkActiveClass() { // Add language. $edit = array( 'predefined_langcode' => 'fr', diff --git a/core/modules/migrate/config/schema/migrate.data_types.schema.yml b/core/modules/migrate/config/schema/migrate.data_types.schema.yml index edb628a..d887785 100644 --- a/core/modules/migrate/config/schema/migrate.data_types.schema.yml +++ b/core/modules/migrate/config/schema/migrate.data_types.schema.yml @@ -14,6 +14,10 @@ migrate_destination: migrate_source: type: migrate_plugin label: 'Source' + mapping: + constants: + type: ignore + label: 'Constants' # Base schema for migrate source plugins that extend # \Drupal\migrate\Plugin\migrate\source\SqlBase. diff --git a/core/modules/migrate/config/schema/migrate.source.schema.yml b/core/modules/migrate/config/schema/migrate.source.schema.yml index d9101a0..f3dae0f 100644 --- a/core/modules/migrate/config/schema/migrate.source.schema.yml +++ b/core/modules/migrate/config/schema/migrate.source.schema.yml @@ -11,6 +11,3 @@ migrate.source.empty: provider: type: string label: 'Provider' - constants: - type: ignore - label: 'Constants' diff --git a/core/modules/migrate_drupal/config/optional/migrate.migration.d6_url_alias.yml b/core/modules/migrate_drupal/config/optional/migrate.migration.d6_url_alias.yml index a8579e9..454ded8 100644 --- a/core/modules/migrate_drupal/config/optional/migrate.migration.d6_url_alias.yml +++ b/core/modules/migrate_drupal/config/optional/migrate.migration.d6_url_alias.yml @@ -4,10 +4,20 @@ migration_tags: - Drupal 6 source: plugin: d6_url_alias + constants: + slash: '/' process: - source: src - alias: dst + source: + plugin: concat + source: + - constants/slash + - src + alias: + plugin: concat + source: + - constants/slash + - dst langcode: language destination: diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php index 091f85c..eae71e4 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUrlAliasTest.php @@ -73,7 +73,7 @@ public function testUrlAlias() { $executable->import(); $path = \Drupal::service('path.alias_storage')->load(array('pid' => $path['pid'])); - $this->assertIdentical('new-url-alias', $path['alias']); + $this->assertIdentical('/new-url-alias', $path['alias']); } } diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index c06271d..61f5c5f 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -59,7 +59,7 @@ public function insert() { if ($this->alias) { $entity = $this->getEntity(); - if ($path = \Drupal::service('path.alias_storage')->save($entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode())) { + if ($path = \Drupal::service('path.alias_storage')->save('/' . $entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode())) { $this->pid = $path['pid']; } } @@ -76,7 +76,7 @@ public function update() { // Only save a non-empty alias. elseif ($this->alias) { $entity = $this->getEntity(); - \Drupal::service('path.alias_storage')->save($entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode(), $this->pid); + \Drupal::service('path.alias_storage')->save('/' . $entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode(), $this->pid); } } @@ -86,7 +86,7 @@ public function update() { public function delete() { // Delete all aliases associated with this entity. $entity = $this->getEntity(); - \Drupal::service('path.alias_storage')->delete(array('source' => $entity->urlInfo()->getInternalPath())); + \Drupal::service('path.alias_storage')->delete(array('source' => '/' . $entity->urlInfo()->getInternalPath())); } /** diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index 03f15b3..957484c 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -33,7 +33,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $entity = $items->getEntity(); $path = array(); if (!$entity->isNew()) { - $conditions = array('source' => $entity->urlInfo()->getInternalPath()); + $conditions = array('source' => '/' . $entity->urlInfo()->getInternalPath()); if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) { $conditions['langcode'] = $items->getLangcode(); } @@ -44,7 +44,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen } $path += array( 'pid' => NULL, - 'source' => !$entity->isNew() ? $entity->urlInfo()->getInternalPath() : NULL, + 'source' => !$entity->isNew() ? '/' . $entity->urlInfo()->getInternalPath() : NULL, 'alias' => '', 'langcode' => $items->getLangcode(), ); @@ -58,7 +58,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#default_value' => $path['alias'], '#required' => $element['#required'], '#maxlength' => 255, - '#description' => $this->t('The alternative URL for this content. Use a relative path. For example, enter "about" for the about page.'), + '#description' => $this->t('The alternative URL for this content. Use a relative path. For example, enter "/about" for the about page.'), ); $element['pid'] = array( '#type' => 'value', @@ -85,7 +85,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen */ public static function validateFormElement(array &$element, FormStateInterface $form_state) { // Trim the submitted value of whitespace and slashes. - $alias = trim(trim($element['alias']['#value']), " \\/"); + $alias = rtrim(trim($element['alias']['#value']), " \\/"); if (!empty($alias)) { $form_state->setValueForElement($element['alias'], $alias); @@ -95,6 +95,10 @@ public static function validateFormElement(array &$element, FormStateInterface $ $form_state->setError($element, t('The alias is already in use.')); } } + + if ($alias[0] !== '/') { + $form_state->setError($element, t('The alias needs to start with a slash.')); + } } /** diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index 52ec545..f9846fa 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -34,8 +34,8 @@ public function testShortcutLinkAdd() { // Create an alias for the node so we can test aliases. $path = array( - 'source' => 'node/' . $this->node->id(), - 'alias' => $this->randomMachineName(8), + 'source' => '/node/' . $this->node->id(), + 'alias' => '/' . $this->randomMachineName(8), ); $this->container->get('path.alias_storage')->save($path['source'], $path['alias']); diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php index a309c58..876656c 100644 --- a/core/modules/system/src/Plugin/Condition/RequestPath.php +++ b/core/modules/system/src/Plugin/Condition/RequestPath.php @@ -153,7 +153,7 @@ public function evaluate() { $request = $this->requestStack->getCurrentRequest(); // Compare the lowercase path alias (if any) and internal path. - $path = trim($this->currentPath->getPath($request), '/'); + $path = rtrim($this->currentPath->getPath($request), '/'); $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path)); return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages)); diff --git a/core/modules/system/src/Tests/Path/AliasTest.php b/core/modules/system/src/Tests/Path/AliasTest.php index f1f6bf2..006bb51 100644 --- a/core/modules/system/src/Tests/Path/AliasTest.php +++ b/core/modules/system/src/Tests/Path/AliasTest.php @@ -51,8 +51,8 @@ function testCRUD() { } // Load alias by source path. - $loadedAlias = $aliasStorage->load(array('source' => 'node/1')); - $this->assertEqual($loadedAlias['alias'], 'alias_for_node_1_und', format_string('The last created alias loaded by default.')); + $loadedAlias = $aliasStorage->load(array('source' => '/node/1')); + $this->assertEqual($loadedAlias['alias'], '/alias_for_node_1_und', format_string('The last created alias loaded by default.')); //Update a few aliases foreach ($aliases as $alias) { @@ -90,8 +90,8 @@ function testLookupPath() { // Test the situation where the source is the same for multiple aliases. // Start with a language-neutral alias, which we will override. $path = array( - 'source' => "user/1", - 'alias' => 'foo', + 'source' => "/user/1", + 'alias' => '/foo', ); $aliasStorage->save($path['source'], $path['alias']); @@ -100,8 +100,8 @@ function testLookupPath() { // Create a language specific alias for the default language (English). $path = array( - 'source' => "user/1", - 'alias' => "users/Dries", + 'source' => "/user/1", + 'alias' => "/users/Dries", 'langcode' => 'en', ); $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); @@ -112,16 +112,16 @@ function testLookupPath() { // Create a language-neutral alias for the same path, again. $path = array( - 'source' => "user/1", - 'alias' => 'bar', + 'source' => "/user/1", + 'alias' => '/bar', ); $aliasStorage->save($path['source'], $path['alias']); $this->assertEqual($aliasManager->getAliasByPath($path['source']), "users/Dries", 'English alias still returned after entering a language-neutral alias.'); // Create a language-specific (xx-lolspeak) alias for the same path. $path = array( - 'source' => "user/1", - 'alias' => 'LOL', + 'source' => "/user/1", + 'alias' => '/LOL', 'langcode' => 'xx-lolspeak', ); $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); @@ -132,8 +132,8 @@ function testLookupPath() { // Create a new alias for this path in English, which should override the // previous alias for "user/1". $path = array( - 'source' => "user/1", - 'alias' => 'users/my-new-path', + 'source' => "/user/1", + 'alias' => '/users/my-new-path', 'langcode' => 'en', ); $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); @@ -151,10 +151,10 @@ function testLookupPath() { // Test the situation where the alias and language are the same, but // the source differs. The newer alias record should be returned. - $aliasStorage->save('user/2', 'bar'); + $aliasStorage->save('/user/2', '/bar'); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); - $this->assertEqual($aliasManager->getPathByAlias('bar'), 'user/2', 'Newer alias record is returned when comparing two LanguageInterface::LANGCODE_NOT_SPECIFIED paths with the same alias.'); + $this->assertEqual($aliasManager->getPathByAlias('bar'), '/user/2', 'Newer alias record is returned when comparing two LanguageInterface::LANGCODE_NOT_SPECIFIED paths with the same alias.'); } /** @@ -181,21 +181,21 @@ function testWhitelist() { $this->assertNull($whitelist->get($this->randomMachineName())); // Add an alias for user/1, user should get whitelisted now. - $aliasStorage->save('user/1', $this->randomMachineName()); + $aliasStorage->save('/user/1', '/' . $this->randomMachineName()); $aliasManager->cacheClear(); - $this->assertTrue($whitelist->get('user')); - $this->assertNull($whitelist->get('admin')); + $this->assertTrue($whitelist->get('/user')); + $this->assertNull($whitelist->get('/admin')); $this->assertNull($whitelist->get($this->randomMachineName())); // Add an alias for admin, both should get whitelisted now. - $aliasStorage->save('admin/something', $this->randomMachineName()); + $aliasStorage->save('/admin/something', '/' . $this->randomMachineName()); $aliasManager->cacheClear(); - $this->assertTrue($whitelist->get('user')); - $this->assertTrue($whitelist->get('admin')); + $this->assertTrue($whitelist->get('/user')); + $this->assertTrue($whitelist->get('/admin')); $this->assertNull($whitelist->get($this->randomMachineName())); // Remove the user alias again, whitelist entry should be removed. - $aliasStorage->delete(array('source' => 'user/1')); + $aliasStorage->delete(array('source' => '/user/1')); $aliasManager->cacheClear(); $this->assertNull($whitelist->get('user')); $this->assertTrue($whitelist->get('admin')); diff --git a/core/modules/system/src/Tests/Path/UrlAliasFixtures.php b/core/modules/system/src/Tests/Path/UrlAliasFixtures.php index 550ea76..aa65075 100644 --- a/core/modules/system/src/Tests/Path/UrlAliasFixtures.php +++ b/core/modules/system/src/Tests/Path/UrlAliasFixtures.php @@ -48,23 +48,23 @@ public function dropTables(Connection $connection) { public function sampleUrlAliases() { return array( array( - 'source' => 'node/1', - 'alias' => 'alias_for_node_1_en', + 'source' => '/node/1', + 'alias' => '/alias_for_node_1_en', 'langcode' => 'en' ), array( - 'source' => 'node/2', - 'alias' => 'alias_for_node_2_en', + 'source' => '/node/2', + 'alias' => '/alias_for_node_2_en', 'langcode' => 'en' ), array( - 'source' => 'node/1', - 'alias' => 'alias_for_node_1_fr', + 'source' => '/node/1', + 'alias' => '/alias_for_node_1_fr', 'langcode' => 'fr' ), array( - 'source' => 'node/1', - 'alias' => 'alias_for_node_1_und', + 'source' => '/node/1', + 'alias' => '/alias_for_node_1_und', 'langcode' => 'und' ) ); diff --git a/core/modules/system/src/Tests/Path/UrlAlterFunctionalTest.php b/core/modules/system/src/Tests/Path/UrlAlterFunctionalTest.php index 1988708..d1cb096 100644 --- a/core/modules/system/src/Tests/Path/UrlAlterFunctionalTest.php +++ b/core/modules/system/src/Tests/Path/UrlAlterFunctionalTest.php @@ -40,14 +40,14 @@ function testUrlAlter() { $this->assertUrlOutboundAlter("user/$uid", "user/$name"); // Test that a path always uses its alias. - $path = array('source' => "user/$uid/test1", 'alias' => 'alias/test1'); + $path = array('source' => "/user/$uid/test1", 'alias' => '/alias/test1'); $this->container->get('path.alias_storage')->save($path['source'], $path['alias']); $this->rebuildContainer(); $this->assertUrlInboundAlter('alias/test1', "user/$uid/test1"); $this->assertUrlOutboundAlter("user/$uid/test1", 'alias/test1'); // Test adding an alias via the UI. - $edit = array('source' => "user/$uid/edit", 'alias' => 'alias/test2'); + $edit = array('source' => "/user/$uid/edit", 'alias' => '/alias/test2'); $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); $this->assertText(t('The alias has been saved.')); $this->drupalGet('alias/test2'); diff --git a/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php b/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php index 45011f8..fae5d1b 100644 --- a/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php +++ b/core/modules/system/src/Tests/Plugin/Condition/RequestPathTest.php @@ -86,7 +86,7 @@ public function testConditions() { // Get the request path condition and test and configure it to check against // different patterns and requests. - $pages = "my/pass/page\r\nmy/pass/page2\r\nfoo"; + $pages = "/my/pass/page\r\n/my/pass/page2\r\n/foo"; $request = Request::create('/my/pass/page2'); $this->requestStack->push($request); @@ -95,42 +95,42 @@ public function testConditions() { $condition = $this->pluginManager->createInstance('request_path'); $condition->setConfig('pages', $pages); - $this->aliasManager->addAlias('my/pass/page2', 'my/pass/page2'); + $this->aliasManager->addAlias('/my/pass/page2', '/my/pass/page2'); $this->assertTrue($condition->execute(), 'The request path matches a standard path'); - $this->assertEqual($condition->summary(), 'Return true on the following pages: my/pass/page, my/pass/page2, foo', 'The condition summary matches for a standard path'); + $this->assertEqual($condition->summary(), 'Return true on the following pages: /my/pass/page, /my/pass/page2, /foo', 'The condition summary matches for a standard path'); // Test an aliased path. $this->currentPath->setPath('/my/aliased/page', $request); $this->requestStack->pop(); $this->requestStack->push($request); - $this->aliasManager->addAlias('my/aliased/page', 'my/pass/page'); + $this->aliasManager->addAlias('/my/aliased/page', '/my/pass/page'); $this->assertTrue($condition->execute(), 'The request path matches an aliased path'); - $this->assertEqual($condition->summary(), 'Return true on the following pages: my/pass/page, my/pass/page2, foo', 'The condition summary matches for an aliased path'); + $this->assertEqual($condition->summary(), 'Return true on the following pages: /my/pass/page, /my/pass/page2, /foo', 'The condition summary matches for an aliased path'); // Test a wildcard path. - $this->aliasManager->addAlias('my/pass/page3', 'my/pass/page3'); + $this->aliasManager->addAlias('/my/pass/page3', '/my/pass/page3'); $this->currentPath->setPath('/my/pass/page3', $request); $this->requestStack->pop(); $this->requestStack->push($request); - $condition->setConfig('pages', 'my/pass/*'); + $condition->setConfig('pages', '/my/pass/*'); $this->assertTrue($condition->evaluate(), 'The system_path my/pass/page3 passes for wildcard paths.'); - $this->assertEqual($condition->summary(), 'Return true on the following pages: my/pass/*', 'The condition summary matches for a wildcard path'); + $this->assertEqual($condition->summary(), 'Return true on the following pages: /my/pass/*', 'The condition summary matches for a wildcard path'); // Test a missing path. $this->requestStack->pop(); $this->requestStack->push($request); $this->currentPath->setPath('/my/fail/page4', $request); - $condition->setConfig('pages', 'my/pass/*'); + $condition->setConfig('pages', '/my/pass/*'); - $this->aliasManager->addAlias('my/fail/page4', 'my/fail/page4'); + $this->aliasManager->addAlias('/my/fail/page4', '/my/fail/page4'); - $this->assertFalse($condition->evaluate(), 'The system_path my/pass/page4 fails for a missing path.'); + $this->assertFalse($condition->evaluate(), 'The system_path /my/pass/page4 fails for a missing path.'); } } diff --git a/core/modules/system/src/Tests/Routing/MockAliasManager.php b/core/modules/system/src/Tests/Routing/MockAliasManager.php index 6c3839d..a832432 100644 --- a/core/modules/system/src/Tests/Routing/MockAliasManager.php +++ b/core/modules/system/src/Tests/Routing/MockAliasManager.php @@ -55,6 +55,13 @@ class MockAliasManager implements AliasManagerInterface { public function addAlias($path, $alias, $path_language = NULL) { $language = $path_language ?: $this->defaultLanguage; + if ($path[0] !== '/') { + throw new \InvalidArgumentException('The path needs to start with a slash.'); + } + if ($alias[0] !== '/') { + throw new \InvalidArgumentException('The alias needs to start with a slash.'); + } + $this->aliases[$path][$language] = $alias; $this->systemPaths[$alias][$language] = $path; } diff --git a/core/tests/Drupal/Tests/Core/Path/AliasManagerTest.php b/core/tests/Drupal/Tests/Core/Path/AliasManagerTest.php index 67bfed0..dfc7d63 100644 --- a/core/tests/Drupal/Tests/Core/Path/AliasManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Path/AliasManagerTest.php @@ -88,7 +88,7 @@ protected function setUp() { * @covers ::getPathByAlias */ public function testGetPathByAliasNoMatch() { - $alias = $this->randomMachineName(); + $alias = '/' . $this->randomMachineName(); $language = new Language(array('id' => 'en')); @@ -157,7 +157,7 @@ public function testGetPathByAliasLangcode() { * @covers ::getAliasByPath */ public function testGetAliasByPathWhitelist() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; @@ -182,7 +182,7 @@ public function testGetAliasByPathWhitelist() { * @covers ::getAliasByPath */ public function testGetAliasByPathNoMatch() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; @@ -219,7 +219,7 @@ public function testGetAliasByPathNoMatch() { * @covers ::writeCache */ public function testGetAliasByPathMatch() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; $alias = $this->randomMachineName(); @@ -257,7 +257,7 @@ public function testGetAliasByPathMatch() { * @covers ::writeCache */ public function testGetAliasByPathCachedMatch() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; $alias = $this->randomMachineName(); @@ -304,7 +304,7 @@ public function testGetAliasByPathCachedMatch() { * @covers ::writeCache */ public function testGetAliasByPathCachedMissLanguage() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; $alias = $this->randomMachineName(); @@ -357,7 +357,7 @@ public function testGetAliasByPathCachedMissLanguage() { * @covers ::writeCache */ public function testGetAliasByPathCachedMissNoAlias() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; $cached_path = $this->randomMachineName(); @@ -405,7 +405,7 @@ public function testGetAliasByPathCachedMissNoAlias() { * @covers ::writeCache */ public function testGetAliasByPathUncachedMissNoAlias() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; $cached_path = $this->randomMachineName(); @@ -455,8 +455,8 @@ public function testGetAliasByPathUncachedMissNoAlias() { * @covers ::cacheClear */ public function testCacheClear() { - $path = 'path'; - $alias = 'alias'; + $path = '/path'; + $alias = '/alias'; $language = $this->setUpCurrentLanguage(); $this->aliasStorage->expects($this->exactly(2)) ->method('lookupPathAlias') @@ -495,7 +495,7 @@ public function testCacheClear() { * @covers ::writeCache */ public function testGetAliasByPathUncachedMissWithAlias() { - $path_part1 = $this->randomMachineName(); + $path_part1 = '/' . $this->randomMachineName(); $path_part2 = $this->randomMachineName(); $path = $path_part1 . '/' . $path_part2; $cached_path = $this->randomMachineName(); diff --git a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php index ad8882e..1d1aaf7 100644 --- a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php @@ -68,43 +68,43 @@ public function getMatchPathData() { return array( array( // Single absolute paths. - 'example/1', + '/example/1', array( - 'example/1' => TRUE, - 'example/2' => FALSE, - 'test' => FALSE, + '/example/1' => TRUE, + '/example/2' => FALSE, + '/test' => FALSE, ), ), array( // Single paths with wildcards. - 'example/*', + '/example/*', array( - 'example/1' => TRUE, - 'example/2' => TRUE, - 'example/3/edit' => TRUE, - 'example/' => TRUE, - 'example' => FALSE, - 'test' => FALSE, + '/example/1' => TRUE, + '/example/2' => TRUE, + '/example/3/edit' => TRUE, + '/example/' => TRUE, + '/example' => FALSE, + '/test' => FALSE, ), ), array( // Single paths with multiple wildcards. - 'node/*/revisions/*', + '/node/*/revisions/*', array( - 'node/1/revisions/3' => TRUE, - 'node/345/revisions/test' => TRUE, - 'node/23/edit' => FALSE, - 'test' => FALSE, + '/node/1/revisions/3' => TRUE, + '/node/345/revisions/test' => TRUE, + '/node/23/edit' => FALSE, + '/test' => FALSE, ), ), array( // Single paths with ''. "", array( - 'dummy' => TRUE, - "dummy/" => FALSE, - "dummy/edit" => FALSE, - 'node' => FALSE, + '/dummy' => TRUE, + "/dummy/" => FALSE, + "/dummy/edit" => FALSE, + '/node' => FALSE, '' => FALSE, ), ), @@ -112,11 +112,11 @@ public function getMatchPathData() { // Paths with both '' and wildcards (should not work). "/*", array( - 'dummy' => FALSE, - 'dummy/' => FALSE, - 'dummy/edit' => FALSE, - 'node/12' => FALSE, - '' => FALSE, + '/dummy' => FALSE, + '/dummy/' => FALSE, + '/dummy/edit' => FALSE, + '/node/12' => FALSE, + '/' => FALSE, ), ), array( diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index f4e90de..99c00cc 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -159,12 +159,12 @@ protected function setUp() { public function aliasManagerCallback() { $args = func_get_args(); switch($args[0]) { - case 'test/one': - return 'hello/world'; - case 'test/two/5': - return 'goodbye/cruel/world'; - case '': - return ''; + case '/test/one': + return '/hello/world'; + case '/test/two/5': + return '/goodbye/cruel/world'; + case '/': + return '/'; default: return $args[0]; }