OSDN Git Service

Fix use of Matcher.replaceAll method with backslash in the replacement string
authorNick Clarke <memorius@gmail.com>
Wed, 28 Jul 2010 03:55:24 +0000 (15:55 +1200)
committerRandy Baumgarte <randy@fbn.cx>
Wed, 28 Jul 2010 10:51:34 +0000 (06:51 -0400)
Backslash must be double-escaped here because it has special meaning

src/cx/fbn/nevernote/config/FileManager.java

index db91568..61629db 100644 (file)
@@ -156,7 +156,10 @@ public class FileManager {
     }
 
     private static String toPlatformPathSeparator(String relativePath) {
-        return ALL_PATH_SEPARATORS_REGEX.matcher(relativePath).replaceAll(File.separator);
+               return ALL_PATH_SEPARATORS_REGEX.matcher(relativePath).replaceAll(
+                               // Must double-escape backslashes,
+                               // because they have special meaning in the replacement string of Matcher.replaceAll
+                               (File.separator.equals("\\") ? "\\\\" : File.separator));
     }
 
     private static String slashTerminatePath(String path) {