diff --git a/core/core.services.yml b/core/core.services.yml index 42b5614..aefdaa6 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -387,6 +387,8 @@ services: tags: - { name: path_processor_inbound, priority: 100 } arguments: ['@path.alias_manager'] + path_matcher: + class: Drupal\Core\Path\PathMatcher transliteration: class: Drupal\Core\Transliteration\PHPTransliteration flood: diff --git a/core/lib/Drupal/Core/Path/PathMatcher.php b/core/lib/Drupal/Core/Path/PathMatcher.php new file mode 100644 index 0000000..8289b2f --- /dev/null +++ b/core/lib/Drupal/Core/Path/PathMatcher.php @@ -0,0 +1,36 @@ + with the frontpage. + $to_replace = array( + '/(\r\n?|\n)/', // newlines + '/\\\\\*/', // asterisks + '/(^|\|)\\\\($|\|)/', // + ); + $replacements = array( + '|', + '.*', + '\1' . preg_quote(config('system.site')->get('page.front'), '/') . '\2', + ); + $patterns_quoted = preg_quote($patterns, '/'); + $regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/'; + } + return (bool) preg_match($regexps[$patterns], $path); + } +} diff --git a/core/lib/Drupal/Core/Path/PathMatcherInterface.php b/core/lib/Drupal/Core/Path/PathMatcherInterface.php new file mode 100644 index 0000000..9408d31 --- /dev/null +++ b/core/lib/Drupal/Core/Path/PathMatcherInterface.php @@ -0,0 +1,24 @@ +configuration['pages']); + $pages = Unicode::strtolower($this->configuration['pages']); // Compare the lowercase path alias (if any) and internal path. $request = $this->getContextValue('request'); $alias_manager = $this->getContextValue('alias_manager'); $path = $request->attributes->get('system_path'); - $path_alias = drupal_strtolower($alias_manager->getPathAlias($path)); - return drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages)); + $path_alias = Unicode::strtolower($alias_manager->getPathAlias($path)); + $path_matcher = $this->getContextValue('path_matcher'); + return $path_matcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $path_matcher->matchPath($path, $pages)); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php b/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php index 8cfbd45..8bf71d8 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php @@ -57,7 +57,8 @@ public function testConditions() { $condition = $this->manager->createInstance('request_path') ->setConfig('pages', $pages) ->setContextValue('request', $new_request) - ->setContextValue('alias_manager', $this->container->get('path.alias_manager')); + ->setContextValue('alias_manager', $this->container->get('path.alias_manager')) + ->setContextValue('path_matcher', $this->container->get('path_matcher')); // Check the first configured path and summary. $this->assertTrue($condition->execute(), 'The system_path my/pass/page passes.');