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