diff --git a/core/lib/Drupal/Core/Path/PathMatcher.php b/core/lib/Drupal/Core/Path/PathMatcher.php index ea760c2..fada60a 100644 --- a/core/lib/Drupal/Core/Path/PathMatcher.php +++ b/core/lib/Drupal/Core/Path/PathMatcher.php @@ -46,14 +46,12 @@ public function matchPath($path, array $patterns) { $pattern_string = implode("\n", $patterns); if (!isset($this->regexes[$pattern_string])) { // Convert path settings to a regular expression. - // Therefore replace newlines with a logical or, /* with asterisks and the - // with the frontpage. $to_replace = array( - // newlines. + // Replace newlines with a logical 'or'. '/(\r\n?|\n)/', - // asterisks. + // Quote asterisks. '/\\\\\*/', - // . + // Quote keyword. '/(^|\|)\\\\($|\|)/', ); $replacements = array( diff --git a/core/lib/Drupal/Core/Path/PathMatcherInterface.php b/core/lib/Drupal/Core/Path/PathMatcherInterface.php index 091ef8f..402641b 100644 --- a/core/lib/Drupal/Core/Path/PathMatcherInterface.php +++ b/core/lib/Drupal/Core/Path/PathMatcherInterface.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Path; /** - * Interface for URL path matchers. + * Provides an interface for URL path matchers. */ interface PathMatcherInterface { diff --git a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php index 9594183..adfdc0b 100644 --- a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php @@ -56,29 +56,62 @@ public function setUp() { $this->patterns = "my/pass/page\r\nmy/pass/page2\r\nfoo"; } + /** - * Test that standard paths works with multiple patterns. + * Test that paths matching works with multiple patterns. + * + * @dataProvider getMatchPathData */ - public function testPathsMultiplePatterns() { - $patterns = array('my/pass/page', 'my/pass/page2', 'foo'); - $this->assertTrue($this->pathMatcher->matchPath('my/pass/page', $patterns), 'The path my/pass/page matches.'); - $this->assertTrue($this->pathMatcher->matchPath('my/pass/page2', $patterns), 'The path my/pass/page2 matches.'); + public function testMatchPath($patterns, $paths) { + foreach ($paths as $path) { + $this->assertTrue($this->pathMatcher->matchPath($path, $patterns), "The path $path matches the patterns."); + } } /** - * Test paths match against wildcards. + * Test that standard paths works with multiple patterns. + * + * @dataProvider getNoMatchPathData */ - public function testWildcardPath() { - $patterns = array('my/pass/*'); - $this->assertTrue($this->pathMatcher->matchPath('my/pass/page3', $patterns), 'The path my/pass/page3 matches.'); + public function testNoMatchPath($patterns, $paths) { + foreach ($paths as $path) { + $this->assertFalse($this->pathMatcher->matchPath($path, $patterns), "The path $path does not match the patterns."); + } } /** - * Test a missing path does not match. + * Provides test path data. + * + * @return array + * A nested array of pattern arrays and path arrays. */ - public function testNoMatchPath() { - $patterns = array('my/pass/page', 'my/pass/page2', 'foo'); - $this->assertFalse($this->pathMatcher->matchPath('my/pass/page4', $patterns), 'The path my/pass/page4 does not match.'); + public function getMatchPathData() { + return array( + // Match explicit path pattern. + array( + array('my/pass/page', 'my/pass/page2', 'foo'), + array('my/pass/page', 'my/pass/page2'), + ), + // Match wildcard path pattern. + array( + array('my/pass/*'), + array('my/pass/page3'), + ), + ); } + /** + * Provides test path data for non-matches. + * + * @return array + * A nested array of pattern arrays and path arrays. + */ + public function getNoMatchPathData() { + return array( + array( + array('my/pass/page', 'my/pass/page2', 'foo'), + array('my/pass/page4'), + ), + ); + } }