Skip to content

Commit

Permalink
Use start/end anchors in matchStrings() regex
Browse files Browse the repository at this point in the history
This adds a new test case demonstrating the issue where "com/**" would incorrectly match "com2/foo". The change also necessitated revising an existing test case.
  • Loading branch information
jmikola committed Jan 20, 2023
1 parent cbae583 commit 28056f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function provideMatches()
{
return array(
array(
'com/t?st',
'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 +95,12 @@ public function provideMatches()
'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'),
),
);
}

Expand Down

0 comments on commit 28056f3

Please sign in to comment.