提交 0afcf0de 编写于 作者: S sherman

6866397: (file) PathMatcher with regex syntax doesn't match as expected (win)

Summary: Use unicode_case_insensitive for windows path matcher for now.
Reviewed-by: alanb
上级 c81f3264
...@@ -283,25 +283,15 @@ class WindowsFileSystem ...@@ -283,25 +283,15 @@ class WindowsFileSystem
} }
} }
// match in uppercase // match in unicode_case_insensitive
StringBuilder sb = new StringBuilder(expr.length()); final Pattern pattern = Pattern.compile(expr,
for (int i=0; i<expr.length(); i++) { Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
sb.append(Character.toUpperCase(expr.charAt(i)));
}
expr = sb.toString();
// return matcher // return matcher
final Pattern pattern = Pattern.compile(expr);
return new PathMatcher() { return new PathMatcher() {
@Override @Override
public boolean matches(Path path) { public boolean matches(Path path) {
// match in uppercase return pattern.matcher(path.toString()).matches();
String s = path.toString();
StringBuilder sb = new StringBuilder(s.length());
for (int i=0; i<s.length(); i++) {
sb.append( Character.toUpperCase(s.charAt(i)) );
}
return pattern.matcher(sb).matches();
} }
}; };
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
* @bug 4313887 * @bug 4313887 6866397
* @summary Unit test for java.nio.file.PathMatcher * @summary Unit test for java.nio.file.PathMatcher
*/ */
...@@ -68,6 +68,20 @@ public class Basic { ...@@ -68,6 +68,20 @@ public class Basic {
} }
} }
static void assertRegExMatch(String path, String pattern) {
System.out.format("Test regex pattern: %s", pattern);
Path file = Paths.get(path);
boolean matched = file.getFileSystem()
.getPathMatcher("regex:" + pattern).matches(file);
if (matched) {
System.out.println(" OKAY");
} else {
System.out.println(" ==> UNEXPECTED RESULT!");
failures++;
}
}
public static void main(String[] args) { public static void main(String[] args) {
// basic // basic
assertMatch("foo.html", "foo.html"); assertMatch("foo.html", "foo.html");
...@@ -140,21 +154,13 @@ public class Basic { ...@@ -140,21 +154,13 @@ public class Basic {
assertMatch("one*two", "one\\*two"); assertMatch("one*two", "one\\*two");
} }
// regex syntax // regex syntax
{ assertRegExMatch("foo.html", ".*\\.html");
String pattern = ".*\\.html";
System.out.format("Test regex pattern: %s", pattern); if (System.getProperty("os.name").startsWith("Windows")) {
Path file = Paths.get("foo.html"); assertRegExMatch("foo012", "foo\\d+");
boolean matched = file.getFileSystem() assertRegExMatch("fo o", "fo\\so");
.getPathMatcher("regex:" + pattern).matches(file); assertRegExMatch("foo", "\\w+");
if (matched) {
System.out.println(" OKAY");
} else {
System.out.println(" ==> UNEXPECTED RESULT!");
failures++;
}
} }
// unknown syntax // unknown syntax
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册