Skip to content

Commit 25c5150

Browse files
committed
support windows paths in RegexMatcher
1 parent e7fdc8c commit 25c5150

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

code-assert/src/test/java/guru/nidi/codeassert/pmd/RegexMatcher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public RegexMatcher(List<Pattern> patterns) {
3333
public static Matcher<String> matchesFormat(String format) {
3434
final List<Pattern> patterns = new ArrayList<>();
3535
for (final String line : format.split(lineSeparator())) {
36-
patterns.add(Pattern.compile("\\Q" + line.replace("%d", "\\E\\d+\\Q").replace("\\", "\\\\") + "\\E"));
36+
patterns.add(Pattern.compile(Pattern.quote(line).replace("%d", "\\E\\d+\\Q")));
3737
}
3838
return new RegexMatcher(patterns);
3939
}
@@ -80,6 +80,7 @@ protected void describeMismatchSafely(String item, Description description) {
8080
}
8181

8282
private String pattern(Pattern p) {
83-
return p.pattern().replace("\\Q", "").replace("\\E", "").replace("\\d+", "%d").replace("\\\\", "\\");
83+
return p.pattern().replace("\\d+", "%d").replace("\\Q", "")
84+
.replaceAll("([^\\\\])\\\\E", "$1").replace("\\\\E", "\\E");
8485
}
8586
}

0 commit comments

Comments
 (0)