Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use start/end anchors in matchStrings() regex #1

Merged
merged 3 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
simensen marked this conversation as resolved.
Show resolved Hide resolved
},
"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'),
),
simensen marked this conversation as resolved.
Show resolved Hide resolved
array(
'com/t?st.jsp',
simensen marked this conversation as resolved.
Show resolved Hide resolved
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/**',
simensen marked this conversation as resolved.
Show resolved Hide resolved
array('com/foo'),
array('com2/foo', '_com/foo'),
simensen marked this conversation as resolved.
Show resolved Hide resolved
),
);
}

Expand Down