diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java index de39f4fe..234a92c5 100644 --- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java +++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java @@ -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 ) diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index ebc2dca0..8c1b7bba 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -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")); + } }