[jOOQ/jOOQ#9726] FilePattern matches too many files when wildcards are

being used
This commit is contained in:
Lukas Eder 2020-01-14 16:08:32 +01:00
parent 439238bd98
commit 7ab5709de4

View File

@ -227,14 +227,20 @@ public final class FilePattern {
loaded = true;
}
else {
String prefix = pattern.replaceAll("[*?].*", "");
file = new File(basedir, prefix).getAbsoluteFile();
// [#9726] The wildcard could be in the middle of a path segment, which
// has to be ignored, e.g. the prefix of a/b*/c is a/
String prefix = pattern.replaceAll("[^\\/]*?[*?].*", "");
file = new File(prefix);
if (!file.isAbsolute())
file = new File(basedir, prefix).getAbsoluteFile();
Pattern regex = Pattern.compile("^.*?"
+ pattern
.replace("\\", "/")
.replace(".", "\\.")
.replace("?", ".")
.replace("?", "[^/]")
.replace("**", ".+?")
.replace("*", "[^/]*")
+ "$"
@ -285,6 +291,11 @@ public final class FilePattern {
}
}
@Override
public String toString() {
return pattern;
}
/**
* A callback interface that allows for loading a {@link Source}.
*/