Skip to content

Fixed #191 #192

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

Closed
wants to merge 2 commits into from
Closed
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
27 changes: 19 additions & 8 deletions src/main/java/org/codehaus/plexus/util/SelectorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,32 @@ public static boolean matchPath( String pattern, String str, String separator, b
{
if ( isRegexPrefixedPattern( pattern ) )
{
pattern =
String localPattern =
pattern.substring( REGEX_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );

return str.matches( pattern );
return str.matches( localPattern );
}
else
{
if ( isAntPrefixedPattern( pattern ) )
{
pattern = pattern.substring( ANT_HANDLER_PREFIX.length(),
pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
}
String localPattern = isAntPrefixedPattern( pattern )
? pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() )
: pattern;
final String osRelatedPath = toOSRelatedPath( str, separator );
final String osRelatedPattern = toOSRelatedPath( localPattern, separator );
return matchAntPathPattern( osRelatedPattern, osRelatedPath, separator, isCaseSensitive );
}
}

return matchAntPathPattern( pattern, str, separator, isCaseSensitive );
private static String toOSRelatedPath( String pattern, String separator )
{
if ( "/".equals( separator ) )
{
return pattern.replace( "\\", separator );
}
if ( "\\".equals( separator ) ) {
return pattern.replace( "/", separator );
}
return pattern;
}

static boolean isRegexPrefixedPattern( String pattern )
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,55 @@ public void testMatchPath_WindowsFileSeparator()
// Pattern and target don't start with file separator
assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false ) );
}

@Test
public void testPatternMatchSingleWildCardLinux()
{
assertFalse(SelectorUtils.matchPath(
"/com/test/*",
"/com/test/test/hallo"));
}


@Test
public void testPatternMatchDoubleWildCardCaseInLinux()
{
assertTrue(SelectorUtils.matchPath(
"/com/test/**",
"/com/test/test/hallo"));
}


@Test
public void testPatternMatchDoubleWildCardLinux()
{
assertTrue(SelectorUtils.matchPath(
"/com/test/**",
"/com/test/test/hallo"));
}


@Test
public void testPatternMatchSingleWildCardWindows()
{
assertFalse(SelectorUtils.matchPath(
"D:\\com\\test\\*",
"D:\\com\\test\\test\\hallo"));

assertFalse(SelectorUtils.matchPath(
"D:/com/test/*",
"D:/com/test/test/hallo"));
}

@Test
public void testPatternMatchDoubleWildCardWindows()
{
assertTrue(SelectorUtils.matchPath(
"D:\\com\\test\\**",
"D:\\com\\test\\test\\hallo"));

assertTrue(SelectorUtils.matchPath(
"D:\\com\\test\\**",
"D:/com/test/test/hallo"));
}
}