diff --git a/core/lib/Drupal/Core/Path/PathMatcher.php b/core/lib/Drupal/Core/Path/PathMatcher.php index 9a8a7bf..449ba2b 100644 --- a/core/lib/Drupal/Core/Path/PathMatcher.php +++ b/core/lib/Drupal/Core/Path/PathMatcher.php @@ -48,11 +48,9 @@ public function __construct(ConfigFactoryInterface $config_factory) { /** * {@inheritdoc} */ - public function matchPath($path, array $patterns) { - // Convert array to a string for easier find and replace. - $pattern_string = implode("\n", $patterns); + public function matchPath($path, $patterns) { - if (!isset($this->regexes[$pattern_string])) { + if (!isset($this->regexes[$patterns])) { // Lazy-load front page config. if (!isset($this->frontPage)) { $this->frontPage = $this->configFactory->get('system.site')->get('page.front'); @@ -71,9 +69,9 @@ public function matchPath($path, array $patterns) { '.*', '\1' . preg_quote($this->frontPage, '/') . '\2', ); - $patterns_quoted = preg_quote($pattern_string, '/'); - $this->regexes[$pattern_string] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/'; + $patterns_quoted = preg_quote($patterns, '/'); + $this->regexes[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/'; } - return (bool) preg_match($this->regexes[$pattern_string], $path); + return (bool) preg_match($this->regexes[$patterns], $path); } } diff --git a/core/lib/Drupal/Core/Path/PathMatcherInterface.php b/core/lib/Drupal/Core/Path/PathMatcherInterface.php index 402641b..8c0b800 100644 --- a/core/lib/Drupal/Core/Path/PathMatcherInterface.php +++ b/core/lib/Drupal/Core/Path/PathMatcherInterface.php @@ -17,12 +17,12 @@ * * @param string $path * The path to match. - * @param string[] $patterns - * A set of patterns. + * @param string $patterns + * A set of patterns separated by a newline. * * @return bool * TRUE if the path matches a pattern, FALSE otherwise. */ - public function matchPath($path, array $patterns); + public function matchPath($path, $patterns); } diff --git a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php index adfdc0b..9c36e2a 100644 --- a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php @@ -53,7 +53,6 @@ public function setUp() { ) ); $this->pathMatcher = new PathMatcher($config_factory_stub); - $this->patterns = "my/pass/page\r\nmy/pass/page2\r\nfoo"; } @@ -89,12 +88,12 @@ public function getMatchPathData() { return array( // Match explicit path pattern. array( - array('my/pass/page', 'my/pass/page2', 'foo'), + "my/pass/page\r\nmy/pass/page2\r\nfoo", array('my/pass/page', 'my/pass/page2'), ), // Match wildcard path pattern. array( - array('my/pass/*'), + 'my/pass/*', array('my/pass/page3'), ), ); @@ -109,7 +108,7 @@ public function getMatchPathData() { public function getNoMatchPathData() { return array( array( - array('my/pass/page', 'my/pass/page2', 'foo'), + "my/pass/page\r\nmy/pass/page2\r\nfoo", array('my/pass/page4'), ), );