Skip to content

Commit 0cb74fb

Browse files
committed
Use start/end anchors in matchStrings() regex
This adds a new test case demonstrating the issue where "com/**" would incorrectly match "com2/foo" or "2com/foo". The change also necessitated revising an existing test case, since "t?st" should not match a string with a file extension. The original test case was changed to add an extension to the pattern, and the extension-less pattern was preserved for a new regression test.
1 parent cbae583 commit 0cb74fb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public function provideMatches()
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 provideMatches()
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)