Skip to content

Commit

Permalink
Merge pull request #300 from alps2006/main
Browse files Browse the repository at this point in the history
fix: compatible with windows path in Robolectric test.
  • Loading branch information
tony19 authored Dec 14, 2022
2 parents ca54e1b + 903fd12 commit 2ae4dd4
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FileFinder {

private static final String REGEX_MARKER_START = "(?:\uFFFE)?";
private static final String REGEX_MARKER_END = "(?:\uFFFF)?";
private static final String PATTERN_SEPARATOR = "/"; // separator with slashified path and pattern
private FileProvider fileProvider;

FileFinder(FileProvider fileProvider) {
Expand Down Expand Up @@ -93,10 +94,10 @@ private void findDirs(List<File> files, List<PathPart> pathParts, int index, Lis
}
}

List<PathPart> splitPath(String pattern) {
List<PathPart> splitPath(String pathPattern) {
List<PathPart> parts = new ArrayList<PathPart>();
List<String> literals = new ArrayList<String>();
for (String p : pattern.split(File.separator)) {
for (String p : pathPattern.split(PATTERN_SEPARATOR)) {
final boolean isRegex = p.contains(REGEX_MARKER_START) && p.contains(REGEX_MARKER_END);
p = p.replace(REGEX_MARKER_START, "").replace(REGEX_MARKER_END, "");
if (isRegex) {
Expand All @@ -115,17 +116,17 @@ List<PathPart> splitPath(String pattern) {
return parts;
}

static String regexEscapePath(String path) {
if (path.contains(File.separator)) {
String[] parts = path.split(File.separator);
static String regexEscapePath(String pattern) {
if (pattern.contains(PATTERN_SEPARATOR)) {
String[] parts = pattern.split(PATTERN_SEPARATOR);
for (int i = 0; i < parts.length; i++) {
if (parts[i].length() > 0) {
parts[i] = REGEX_MARKER_START + parts[i] + REGEX_MARKER_END;
}
}
return TextUtils.join(File.separator, parts);
return TextUtils.join(PATTERN_SEPARATOR, parts);
} else {
return REGEX_MARKER_START + path + REGEX_MARKER_END;
return REGEX_MARKER_START + pattern + REGEX_MARKER_END;
}
}

Expand Down Expand Up @@ -182,4 +183,4 @@ boolean matches(File file) {
List<File> listFiles(FileProvider fileProvider) {
return listFiles(fileProvider, ".");
}
}
}

0 comments on commit 2ae4dd4

Please sign in to comment.