diff --git a/core/src/main/java/hudson/tasks/Mailer.java b/core/src/main/java/hudson/tasks/Mailer.java index c3d73c1383..f395dfd6f4 100644 --- a/core/src/main/java/hudson/tasks/Mailer.java +++ b/core/src/main/java/hudson/tasks/Mailer.java @@ -184,7 +184,7 @@ public class Mailer extends Publisher { // workspaceDir will not normally end with one; // workspaceDir.toURI() will end with '/' if and only if workspaceDir.exists() at time of call wsPattern = Pattern.compile("(" + - Pattern.quote(workspaceDir.getPath()) + "|" + Pattern.quote(workspaceDir.toURI().toString()) + ")[/\\\\]?([^:#\\s]*)"); + quoteRegexp(workspaceDir.getPath()) + "|" + quoteRegexp(workspaceDir.toURI().toString()) + ")[/\\\\]?([^:#\\s]*)"); } for (int i = start; i < lines.length; i++) { String line = lines[i]; @@ -414,4 +414,26 @@ public class Mailer extends Publisher { } } } + + /** + * Copied from JDK5, to avoid 5.0 dependency. + */ + private static String quoteRegexp(String s) { + int slashEIndex = s.indexOf("\\E"); + if (slashEIndex == -1) + return "\\Q" + s + "\\E"; + + StringBuilder sb = new StringBuilder(s.length() * 2); + sb.append("\\Q"); + slashEIndex = 0; + int current = 0; + while ((slashEIndex = s.indexOf("\\E", current)) != -1) { + sb.append(s.substring(current, slashEIndex)); + current = slashEIndex + 2; + sb.append("\\E\\\\E\\Q"); + } + sb.append(s.substring(current, s.length())); + sb.append("\\E"); + return sb.toString(); + } }