Skip to content

Commit 2ae4dd4

Browse files
authored
Merge pull request #300 from alps2006/main
fix: compatible with windows path in Robolectric test.
2 parents ca54e1b + 903fd12 commit 2ae4dd4

File tree

1 file changed

+9
-8
lines changed
  • logback-android/src/main/java/ch/qos/logback/core/rolling/helper

1 file changed

+9
-8
lines changed

logback-android/src/main/java/ch/qos/logback/core/rolling/helper/FileFinder.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class FileFinder {
2727

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

3233
FileFinder(FileProvider fileProvider) {
@@ -93,10 +94,10 @@ private void findDirs(List<File> files, List<PathPart> pathParts, int index, Lis
9394
}
9495
}
9596

96-
List<PathPart> splitPath(String pattern) {
97+
List<PathPart> splitPath(String pathPattern) {
9798
List<PathPart> parts = new ArrayList<PathPart>();
9899
List<String> literals = new ArrayList<String>();
99-
for (String p : pattern.split(File.separator)) {
100+
for (String p : pathPattern.split(PATTERN_SEPARATOR)) {
100101
final boolean isRegex = p.contains(REGEX_MARKER_START) && p.contains(REGEX_MARKER_END);
101102
p = p.replace(REGEX_MARKER_START, "").replace(REGEX_MARKER_END, "");
102103
if (isRegex) {
@@ -115,17 +116,17 @@ List<PathPart> splitPath(String pattern) {
115116
return parts;
116117
}
117118

118-
static String regexEscapePath(String path) {
119-
if (path.contains(File.separator)) {
120-
String[] parts = path.split(File.separator);
119+
static String regexEscapePath(String pattern) {
120+
if (pattern.contains(PATTERN_SEPARATOR)) {
121+
String[] parts = pattern.split(PATTERN_SEPARATOR);
121122
for (int i = 0; i < parts.length; i++) {
122123
if (parts[i].length() > 0) {
123124
parts[i] = REGEX_MARKER_START + parts[i] + REGEX_MARKER_END;
124125
}
125126
}
126-
return TextUtils.join(File.separator, parts);
127+
return TextUtils.join(PATTERN_SEPARATOR, parts);
127128
} else {
128-
return REGEX_MARKER_START + path + REGEX_MARKER_END;
129+
return REGEX_MARKER_START + pattern + REGEX_MARKER_END;
129130
}
130131
}
131132

@@ -182,4 +183,4 @@ boolean matches(File file) {
182183
List<File> listFiles(FileProvider fileProvider) {
183184
return listFiles(fileProvider, ".");
184185
}
185-
}
186+
}

0 commit comments

Comments
 (0)