diff --git a/core/lib/Drupal/Core/Path/AliasStorageInterface.php b/core/lib/Drupal/Core/Path/AliasStorageInterface.php index ae79300..5ac77a3 100644 --- a/core/lib/Drupal/Core/Path/AliasStorageInterface.php +++ b/core/lib/Drupal/Core/Path/AliasStorageInterface.php @@ -50,7 +50,7 @@ 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 with a starting lash. + * - 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. diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorFront.php index 3fdcbb7..bd1d8c1 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/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index 9989274..278b486 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -142,7 +142,7 @@ public function getRouteCollectionForRequest(Request $request) { else { // Just trim on the right side. $path = $request->getPathInfo(); - $path = $path == '/' ? $path : rtrim($request->getPathInfo(), '/'); + $path = $path === '/' ? $path : rtrim($request->getPathInfo(), '/'); $path = $this->pathProcessor->processInbound($path, $request); $this->currentPath->setPath($path, $request); // Incoming path processors may also set query parameters. diff --git a/core/modules/config/src/Tests/ConfigSingleImportExportTest.php b/core/modules/config/src/Tests/ConfigSingleImportExportTest.php index 8c8594c..688d867 100644 --- a/core/modules/config/src/Tests/ConfigSingleImportExportTest.php +++ b/core/modules/config/src/Tests/ConfigSingleImportExportTest.php @@ -27,7 +27,7 @@ class ConfigSingleImportExportTest extends WebTestBase { /** * Tests importing a single configuration file. */ - public function tesImport() { + public function testImport() { $storage = \Drupal::entityManager()->getStorage('config_test'); $uuid = \Drupal::service('uuid'); @@ -141,7 +141,7 @@ public function testImportSimpleConfiguration() { /** * Tests exporting a single configuration file. */ - public function tesExport() { + public function testExport() { $this->drupalLogin($this->drupalCreateUser(array('export configuration'))); $this->drupalGet('admin/config/development/configuration/single/export/system.simple'); diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index 3708aa6..e4d07e2 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -176,6 +176,18 @@ function testAdminAlias() { $this->drupalPostForm('admin/config/search/path/edit/' . $pid, $edit, t('Save')); $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['alias']))); + // Create an alias without a starting slash. + $node5 = $this->drupalCreateNode(); + + $edit = array(); + $edit['source'] = 'node/' . $node5->id(); + $node5_alias = $this->randomMachineName(8); + $edit['alias'] = $node5_alias . '/'; + $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); + + $this->assertUrl('admin/config/search/path/add'); + $this->assertText('The source path has to start with a slash.'); + $this->assertText('The alias path has to start with a slash.'); } /** diff --git a/core/modules/system/src/Form/SiteInformationForm.php b/core/modules/system/src/Form/SiteInformationForm.php index af1c83d..1b1e3a6 100644 --- a/core/modules/system/src/Form/SiteInformationForm.php +++ b/core/modules/system/src/Form/SiteInformationForm.php @@ -173,7 +173,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { } // Validate front page path. if (($value = $form_state->getValue('site_frontpage')) && $value[0] !== '/') { - $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' has to start with a /.", ['%path' => $form_state->getValue('site_frontpage')])); + $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_frontpage')])); } if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) { @@ -187,10 +187,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $form_state->setValueForElement($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404'))); } if (($value = $form_state->getValue('site_403')) && $value[0] !== '/') { - $form_state->setErrorByName('site_403', $this->t("The path '%path' has to start with a /.", ['%path' => $form_state->getValue('site_403')])); + $form_state->setErrorByName('site_403', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_403')])); } if (($value = $form_state->getValue('site_404')) && $value[0] !== '/') { - $form_state->setErrorByName('site_404', $this->t("The path '%path' has to start with a /.", ['%path' => $form_state->getValue('site_404')])); + $form_state->setErrorByName('site_404', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_404')])); } // Validate 403 error path. if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) { diff --git a/core/modules/system/src/Tests/System/AccessDeniedTest.php b/core/modules/system/src/Tests/System/AccessDeniedTest.php index 1553421..0f37320 100644 --- a/core/modules/system/src/Tests/System/AccessDeniedTest.php +++ b/core/modules/system/src/Tests/System/AccessDeniedTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\System; +use Drupal\Component\Utility\SafeMarkup; use Drupal\simpletest\WebTestBase; use Drupal\user\RoleInterface; @@ -41,8 +42,16 @@ function testAccessDenied() { $this->assertText(t('Access denied'), 'Found the default 403 page'); $this->assertResponse(403); - // Use a custom 403 page. $this->drupalLogin($this->adminUser); + + // Set a custom 404 page without a starting slash. + $edit = [ + 'site_403' => 'user/' . $this->adminUser->id(), + ]; + $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration')); + $this->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", ['%path' => $edit['site_403']])); + + // Use a custom 403 page. $edit = [ 'site_403' => '/user/' . $this->adminUser->id(), ]; diff --git a/core/modules/system/src/Tests/System/FrontPageTest.php b/core/modules/system/src/Tests/System/FrontPageTest.php index 34a3aeb..88235b3 100644 --- a/core/modules/system/src/Tests/System/FrontPageTest.php +++ b/core/modules/system/src/Tests/System/FrontPageTest.php @@ -71,6 +71,11 @@ public function testDrupalFrontPage() { $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration')); $this->assertText(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $edit['site_frontpage']))); + // Change the front page to a path without a starting slash. + $edit = ['site_frontpage' => $this->nodePath]; + $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration')); + $this->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", ['%path' => $edit['site_frontpage']])); + // Change the front page to a valid path. $edit['site_frontpage'] = '/' . $this->nodePath; $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration')); diff --git a/core/modules/system/src/Tests/System/PageNotFoundTest.php b/core/modules/system/src/Tests/System/PageNotFoundTest.php index 7ebff3e..b7c0609 100644 --- a/core/modules/system/src/Tests/System/PageNotFoundTest.php +++ b/core/modules/system/src/Tests/System/PageNotFoundTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\System; +use Drupal\Component\Utility\SafeMarkup; use Drupal\simpletest\WebTestBase; use Drupal\user\RoleInterface; @@ -33,6 +34,13 @@ function testPageNotFound() { $this->drupalGet($this->randomMachineName(10)); $this->assertText(t('Page not found'), 'Found the default 404 page'); + // Set a custom 404 page without a starting slash. + $edit = [ + 'site_404' => 'user/' . $this->adminUser->id(), + ]; + $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration')); + $this->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", ['%path' => $edit['site_404']])); + // Use a custom 404 page. $edit = array( 'site_404' => '/user/' . $this->adminUser->id(),