diff --git a/core/lib/Drupal/Core/Path/AliasStorage.php b/core/lib/Drupal/Core/Path/AliasStorage.php index 4385923..899c39e 100644 --- a/core/lib/Drupal/Core/Path/AliasStorage.php +++ b/core/lib/Drupal/Core/Path/AliasStorage.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Path; use Drupal\Core\Cache\Cache; -use Drupal\Component\Utility\Unicode; use Drupal\Core\Database\Connection; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageInterface; @@ -99,8 +98,7 @@ public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NO public function load($conditions) { $select = $this->connection->select('url_alias'); foreach ($conditions as $field => $value) { - // Use LIKE for case-insensitive matching. - $select->condition($field, $value, 'LIKE'); + $select->condition($field, $value); } return $select ->fields('url_alias') @@ -117,8 +115,7 @@ public function delete($conditions) { $path = $this->load($conditions); $query = $this->connection->delete('url_alias'); foreach ($conditions as $field => $value) { - // Use LIKE for case-insensitive matching. - $query->condition($field, $value, 'LIKE'); + $query->condition($field, $value); } $deleted = $query->execute(); // @todo Switch to using an event for this instead of a hook. @@ -132,6 +129,7 @@ public function delete($conditions) { */ public function preloadPathAlias($preloaded, $langcode) { $args = array( + ':system[]' => $preloaded, ':langcode' => $langcode, ':langcode_undetermined' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ); @@ -142,22 +140,19 @@ public function preloadPathAlias($preloaded, $langcode) { // created alias for each source. Subsequent queries using fetchField() must // use pid DESC to have the same effect. For performance reasons, the query // builder is not used here. - $select = $this->connection->select('url_alias'); - $select->fields('url_alias', ['source', 'alias']); - $select->condition('source', $preloaded, 'IN'); if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { - // Don't put the same value in the IN query twice. + // Prevent PDO from complaining about a token the query doesn't use. unset($args[':langcode']); + $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN ( :system[] ) AND langcode = :langcode_undetermined ORDER BY pid ASC', $args); } elseif ($langcode < LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $select->orderBy('langcode', 'ASC'); + $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN ( :system[] ) AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid ASC', $args); } else { - $select->orderBy('langcode', 'DESC'); + $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN ( :system[] ) AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid ASC', $args); } - $select->condition('langcode', $args, 'IN'); - $select->orderBy('pid', 'ASC'); - return $select->execute()->fetchAllKeyed(); + + return $result->fetchAllKeyed(); } /** @@ -165,26 +160,23 @@ public function preloadPathAlias($preloaded, $langcode) { */ public function lookupPathAlias($path, $langcode) { $args = array( + ':source' => $path, ':langcode' => $langcode, ':langcode_undetermined' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ); // See the queries above. - $select = $this->connection->select('url_alias'); - $select->fields('url_alias', ['alias']); if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { unset($args[':langcode']); + $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode = :langcode_undetermined ORDER BY pid DESC", $args)->fetchField(); } elseif ($langcode > LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $select->orderBy('langcode', 'DESC'); + $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid DESC", $args)->fetchField(); } else { - $select->orderBy('langcode', 'ASC'); + $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid DESC", $args)->fetchField(); } - // Use LIKE for case-insensitive matching. - $select->condition('source', $path, 'LIKE'); - $select->condition('langcode', $args, 'IN'); - $select->orderBy('pid', 'DESC'); - return $select->execute()->fetchField(); + + return $alias; } /** @@ -192,26 +184,23 @@ public function lookupPathAlias($path, $langcode) { */ public function lookupPathSource($path, $langcode) { $args = array( + ':alias' => $path, ':langcode' => $langcode, ':langcode_undetermined' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ); // See the queries above. - $select = $this->connection->select('url_alias'); - $select->fields('url_alias', ['source']); if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { unset($args[':langcode']); + $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode = :langcode_undetermined ORDER BY pid DESC", $args); } elseif ($langcode > LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $select->orderBy('langcode', 'DESC'); + $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid DESC", $args); } else { - $select->orderBy('langcode', 'ASC'); + $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid DESC", $args); } - // Use LIKE for case-insensitive matching. - $select->condition('alias', $path, 'LIKE'); - $select->condition('langcode', $args, 'IN'); - $select->orderBy('pid', 'DESC'); - return $select->execute()->fetchField(); + + return $result->fetchField(); } /** @@ -219,8 +208,7 @@ public function lookupPathSource($path, $langcode) { */ public function aliasExists($alias, $langcode, $source = NULL) { $query = $this->connection->select('url_alias') - // Use LIKE for case-insensitive matching. - ->condition('alias', $alias, 'LIKE') + ->condition('alias', $alias) ->condition('langcode', $langcode); if (!empty($source)) { $query->condition('source', $source, '<>'); diff --git a/core/lib/Drupal/Core/Path/AliasStorageInterface.php b/core/lib/Drupal/Core/Path/AliasStorageInterface.php index 7717aef..5ac77a3 100644 --- a/core/lib/Drupal/Core/Path/AliasStorageInterface.php +++ b/core/lib/Drupal/Core/Path/AliasStorageInterface.php @@ -135,9 +135,8 @@ public function languageAliasExists(); * * @param array $header * Table header. - * @param string|null $keys - * (optional) Search keyword that may include one or more '*' as a wildcard - * value. + * @param string[]|null $keys + * (optional) Search keys. * * @return array * Array of items to be displayed on the current page. diff --git a/core/modules/locale/src/Tests/LocalePathTest.php b/core/modules/locale/src/Tests/LocalePathTest.php index b04d4e3..820814e 100644 --- a/core/modules/locale/src/Tests/LocalePathTest.php +++ b/core/modules/locale/src/Tests/LocalePathTest.php @@ -7,7 +7,6 @@ namespace Drupal\locale\Tests; -use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Url; use Drupal\simpletest\WebTestBase; @@ -73,7 +72,7 @@ public function testPathLanguageConfiguration() { // Create a path alias in default language (English). $path = 'admin/config/search/path/add'; - $english_path = Unicode::strtolower($this->randomMachineName(8)); + $english_path = $this->randomMachineName(8); $edit = array( 'source' => '/node/' . $node->id(), 'alias' => '/' . $english_path, @@ -82,7 +81,7 @@ public function testPathLanguageConfiguration() { $this->drupalPostForm($path, $edit, t('Save')); // Create a path alias in new custom language. - $custom_language_path = Unicode::strtolower($this->randomMachineName(8)); + $custom_language_path = $this->randomMachineName(8); $edit = array( 'source' => '/node/' . $node->id(), 'alias' => '/' . $custom_language_path, @@ -99,7 +98,7 @@ public function testPathLanguageConfiguration() { $this->assertText($node->label(), 'Custom language alias works.'); // Create a custom path. - $custom_path = Unicode::strtolower($this->randomMachineName(8)); + $custom_path = $this->randomMachineName(8); // Check priority of language for alias by source path. $edit = array( diff --git a/core/modules/path/path.module b/core/modules/path/path.module index dbb8d97..307a08b 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -21,13 +21,12 @@ function path_help($route_name, RouteMatchInterface $route_match) { $output = ''; $output .= '

' . t('About') . '

'; $output .= '

' . t('The Path module allows you to specify an alias, or custom URL, for any existing internal system path. Aliases should not be confused with URL redirects, which allow you to forward a changed or inactive URL to a new URL. In addition to making URLs more readable, aliases also help search engines index content more effectively. Multiple aliases may be used for a single internal system path. To automate the aliasing of paths, you can install the contributed module Pathauto. For more information, see the online documentation for the Path module.', array(':path' => 'https://www.drupal.org/documentation/modules/path', ':pathauto' => 'https://www.drupal.org/project/pathauto')) . '

'; - $output .= '

' . t('Aliases must be unique, are converted to lowercase, and are matched in a case insensitive fashion.'); $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating aliases') . '
'; - $output .= '
' . t('If you create or edit a taxonomy term you can add a unique alias (for example /music/jazz) in the field "URL alias". When creating or editing content you can add an alias (for example /about-us/team) under the section "URL path settings" in the field "URL alias". Aliases for any other path can be added through the page URL aliases. To add aliases a user needs the permission Create and edit URL aliases.', array(':aliases' => \Drupal::url('path.admin_overview'), ':permissions' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-path')))) . '
'; + $output .= '
' . t('If you create or edit a taxonomy term you can add an alias (for example music/jazz) in the field "URL alias". When creating or editing content you can add an alias (for example about-us/team) under the section "URL path settings" in the field "URL alias". Aliases for any other path can be added through the page URL aliases. To add aliases a user needs the permission Create and edit URL aliases.', array(':aliases' => \Drupal::url('path.admin_overview'), ':permissions' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-path')))) . '
'; $output .= '
' . t('Managing aliases') . '
'; - $output .= '
' . t('The Path module provides a way to search and view a list of all aliases that are in use on your website. Aliases need to be unique and are converted to lowercase. Aliases can be added, edited and deleted through this list.', array(':aliases' => \Drupal::url('path.admin_overview'))) . '
'; + $output .= '
' . t('The Path module provides a way to search and view a list of all aliases that are in use on your website. Aliases can be added, edited and deleted through this list.', array(':aliases' => \Drupal::url('path.admin_overview'))) . '
'; $output .= '
'; return $output; diff --git a/core/modules/path/src/Form/PathFormBase.php b/core/modules/path/src/Form/PathFormBase.php index e296b6c..8c84841 100644 --- a/core/modules/path/src/Form/PathFormBase.php +++ b/core/modules/path/src/Form/PathFormBase.php @@ -116,7 +116,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $pid = NU '#default_value' => $this->path['alias'], '#maxlength' => 255, '#size' => 45, - '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page. Use a relative path with a slash in front. The path alias will be converted to lowercase and must be unique.'), + '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page. Use a relative path with a slash in front..'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), '#required' => TRUE, ); diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index 063e988..651c11f 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -7,7 +7,6 @@ namespace Drupal\path\Tests; -use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\Cache; /** @@ -83,13 +82,6 @@ function testAdminAlias() { $this->drupalGet($edit['alias']); $this->assertText($node1->label(), 'Alias works.'); $this->assertResponse(200); - // Confirm that the alias works in a case-insensitive way. - $this->drupalGet(Unicode::strtolower($edit['alias'])); - $this->assertText($node1->label(), 'Alias works lower case.'); - $this->assertResponse(200); - $this->drupalGet(Unicode::strtoupper($edit['alias'])); - $this->assertText($node1->label(), 'Alias works upper case.'); - $this->assertResponse(200); // Change alias to one containing "exotic" characters. $pid = $this->getPID($edit['alias']); diff --git a/core/modules/system/src/Tests/Menu/MenuRouterTest.php b/core/modules/system/src/Tests/Menu/MenuRouterTest.php index deefc99..68b6657 100644 --- a/core/modules/system/src/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/src/Tests/Menu/MenuRouterTest.php @@ -67,7 +67,7 @@ public function testMenuIntegration() { */ protected function doTestHookMenuIntegration() { // Generate base path with random argument. - $machine_name = Unicode::strtolower($this->randomMachineName(8)); + $machine_name = $this->randomMachineName(8); $base_path = 'foo/' . $machine_name; $this->drupalGet($base_path); // Confirm correct controller activated. diff --git a/core/modules/views/src/Tests/Wizard/MenuTest.php b/core/modules/views/src/Tests/Wizard/MenuTest.php index ffae5bc..93c11c5 100644 --- a/core/modules/views/src/Tests/Wizard/MenuTest.php +++ b/core/modules/views/src/Tests/Wizard/MenuTest.php @@ -8,7 +8,6 @@ namespace Drupal\views\Tests\Wizard; use Drupal\Component\Utility\SafeMarkup; -use Drupal\Component\Utility\Unicode; use Drupal\Core\Url; /** @@ -31,7 +30,7 @@ function testMenus() { $view['description'] = $this->randomMachineName(16); $view['page[create]'] = 1; $view['page[title]'] = $this->randomMachineName(16); - $view['page[path]'] = Unicode::strtolower($this->randomMachineName(16)); + $view['page[path]'] = strtolower($this->randomMachineName(16)); $view['page[link]'] = 1; $view['page[link_properties][menu_name]'] = 'main'; $view['page[link_properties][title]'] = $this->randomMachineName(16);