Skip to content

Commit c8406d2

Browse files
authored
Merge pull request #1 from jmikola/fix-matchStrings
Use start/end anchors in matchStrings() regex
2 parents 66e0ed7 + 0cb74fb commit c8406d2

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"require": {
2121
"php": ">=5.3"
2222
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^4|^5|^6|^7|^8|^9"
25+
},
2326
"autoload": {
2427
"psr-0": { "dflydev\\util\\antPathMatcher": "src" }
2528
}

src/dflydev/util/antPathMatcher/AntPathMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ protected function matchStrings($pattern, $str)
221221
{
222222
$re = preg_replace_callback('([\?\*\.\+])', array($this, 'matchStringsCallback'), $pattern);
223223

224-
return preg_match('/'.$re.'/', $str);
224+
return preg_match('/^'.$re.'$/', $str);
225225
}
226226

227227
}

tests/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010

1111
$loader = require dirname(__DIR__).'/vendor/autoload.php';
1212
$loader->add('dflydev\\tests\\util\\antPathMatcher', 'tests');
13+
14+
if (class_exists('PHPUnit\Framework\TestCase') && ! class_exists('PHPUnit_Framework_TestCase')) {
15+
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
16+
}

tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testLeadingPathCharacterMismatch() {
3030
}
3131

3232
/**
33-
* @dataProvider testMatchesProvider
33+
* @dataProvider provideMatches
3434
*/
3535
public function testMatches($pattern, $shouldMatch, $shouldNotMatch)
3636
{
@@ -48,11 +48,16 @@ public function formatTestMatchesMessage($pattern, $path)
4848
return 'Testing path "' . $path . '" against pattern "' . $pattern . '"';
4949
}
5050

51-
public function testMatchesProvider()
51+
public function provideMatches()
5252
{
5353
return array(
5454
array(
5555
'com/t?st',
56+
array('com/test', 'com/tast', 'com/txst'),
57+
array('com/test.jsp', 'com/tast.jsp', 'com/txst.jsp'),
58+
),
59+
array(
60+
'com/t?st.jsp',
5661
array('com/test.jsp', 'com/tast.jsp', 'com/txst.jsp'),
5762
array('com/toast.jsp', 'com/README.md')
5863
),
@@ -95,7 +100,12 @@ public function testMatchesProvider()
95100
'com/foo/',
96101
array('com/foo/bar.jsp','com/foo/bar/baz.jsp',),
97102
array('com.txt', 'com/foo.txt'),
98-
)
103+
),
104+
array(
105+
'com/**',
106+
array('com/foo'),
107+
array('com2/foo', '_com/foo'),
108+
),
99109
);
100110
}
101111

0 commit comments

Comments
 (0)