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('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 .= '