Skip to content

Commit d062bd0

Browse files
author
Niall Pemberton
committed
IO-246 FilenameUtils - wildcardMatch gives incorrect results - thanks to wa
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1002582 13f79535-47bb-0310-9956-ffa450edef68
1 parent ed01f16 commit d062bd0

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,9 @@ public static boolean wildcardMatch(String filename, String wildcardMatcher, IOC
12641264
if (wcs[wcsIdx].equals("?")) {
12651265
// ? so move to next text char
12661266
textIdx++;
1267+
if (textIdx > filename.length()) {
1268+
break;
1269+
}
12671270
anyChars = false;
12681271

12691272
} else if (wcs[wcsIdx].equals("*")) {

src/test/org/apache/commons/io/FilenameUtilsWildcardTestCase.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,30 @@ public void testMatch2() {
182182
assertMatch("log.log.abc.log.abc.d", "*log?abc?d", true);
183183
}
184184

185+
/**
186+
* See https://issues.apache.org/jira/browse/IO-246
187+
*/
188+
public void test_IO_246() {
189+
190+
// Tests for "*?"
191+
assertMatch("aaa", "*?", false);
192+
193+
// Tests for "?*"
194+
assertMatch("", "?*", false);
195+
assertMatch("a", "a?*", false);
196+
assertMatch("aa", "aa?*", false);
197+
assertMatch("a", "?*", true);
198+
assertMatch("aa", "?*", true);
199+
assertMatch("aaa", "?*", true);
200+
201+
// Test ending on "?"
202+
assertMatch("", "?", false);
203+
assertMatch("a", "a?", false);
204+
assertMatch("aa", "aa?", false);
205+
assertMatch("aab", "aa?", true);
206+
assertMatch("aaa", "*a", true);
207+
}
208+
185209
public void testLocaleIndependence() {
186210
Locale orig = Locale.getDefault();
187211

0 commit comments

Comments
 (0)