Skip to content

Commit

Permalink
Merge pull request #1 from jmikola/fix-matchStrings
Browse files Browse the repository at this point in the history
Use start/end anchors in matchStrings() regex
  • Loading branch information
simensen committed Jan 23, 2023
2 parents 66e0ed7 + 0cb74fb commit c8406d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"require": {
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "^4|^5|^6|^7|^8|^9"
},
"autoload": {
"psr-0": { "dflydev\\util\\antPathMatcher": "src" }
}
Expand Down
2 changes: 1 addition & 1 deletion src/dflydev/util/antPathMatcher/AntPathMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected function matchStrings($pattern, $str)
{
$re = preg_replace_callback('([\?\*\.\+])', array($this, 'matchStringsCallback'), $pattern);

return preg_match('/'.$re.'/', $str);
return preg_match('/^'.$re.'$/', $str);
}

}
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@

$loader = require dirname(__DIR__).'/vendor/autoload.php';
$loader->add('dflydev\\tests\\util\\antPathMatcher', 'tests');

if (class_exists('PHPUnit\Framework\TestCase') && ! class_exists('PHPUnit_Framework_TestCase')) {
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
}
16 changes: 13 additions & 3 deletions tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testLeadingPathCharacterMismatch() {
}

/**
* @dataProvider testMatchesProvider
* @dataProvider provideMatches
*/
public function testMatches($pattern, $shouldMatch, $shouldNotMatch)
{
Expand All @@ -48,11 +48,16 @@ public function formatTestMatchesMessage($pattern, $path)
return 'Testing path "' . $path . '" against pattern "' . $pattern . '"';
}

public function testMatchesProvider()
public function provideMatches()
{
return array(
array(
'com/t?st',
array('com/test', 'com/tast', 'com/txst'),
array('com/test.jsp', 'com/tast.jsp', 'com/txst.jsp'),
),
array(
'com/t?st.jsp',
array('com/test.jsp', 'com/tast.jsp', 'com/txst.jsp'),
array('com/toast.jsp', 'com/README.md')
),
Expand Down Expand Up @@ -95,7 +100,12 @@ public function testMatchesProvider()
'com/foo/',
array('com/foo/bar.jsp','com/foo/bar/baz.jsp',),
array('com.txt', 'com/foo.txt'),
)
),
array(
'com/**',
array('com/foo'),
array('com2/foo', '_com/foo'),
),
);
}

Expand Down

0 comments on commit c8406d2

Please sign in to comment.