From 903fd12e3c1084f40568a1c355209662e2350d63 Mon Sep 17 00:00:00 2001 From: alps2006 Date: Wed, 7 Dec 2022 19:12:20 +0800 Subject: [PATCH] fix: compatible with windows path in Robolectric test. --- .../logback/core/rolling/helper/FileFinder.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/logback-android/src/main/java/ch/qos/logback/core/rolling/helper/FileFinder.java b/logback-android/src/main/java/ch/qos/logback/core/rolling/helper/FileFinder.java index 10a001aad6..b07b4fdd94 100644 --- a/logback-android/src/main/java/ch/qos/logback/core/rolling/helper/FileFinder.java +++ b/logback-android/src/main/java/ch/qos/logback/core/rolling/helper/FileFinder.java @@ -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) { @@ -93,10 +94,10 @@ private void findDirs(List files, List pathParts, int index, Lis } } - List splitPath(String pattern) { + List splitPath(String pathPattern) { List parts = new ArrayList(); List literals = new ArrayList(); - 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) { @@ -115,17 +116,17 @@ List 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; } } @@ -182,4 +183,4 @@ boolean matches(File file) { List listFiles(FileProvider fileProvider) { return listFiles(fileProvider, "."); } -} \ No newline at end of file +}