From 1efac50834a5efb3c805ac378c66982b9ac87019 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Fri, 11 Apr 2014 22:35:46 -0700 Subject: [PATCH] Directories named after albums are sanitized first --- .../java/com/rarchives/ripme/ripper/AbstractRipper.java | 4 +++- src/main/java/com/rarchives/ripme/utils/Utils.java | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java index 1f2a3b27..f680d8c4 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java @@ -264,7 +264,9 @@ public abstract class AbstractRipper if (!path.endsWith(File.separator)) { path += File.separator; } - path += getAlbumTitle(this.url) + File.separator; + String title = getAlbumTitle(this.url); + title = Utils.filesystemSafe(title); + path += title + File.separator; this.workingDir = new File(path); if (!this.workingDir.exists()) { logger.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir)); diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index c8fe6e7c..8d20837d 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -241,4 +241,10 @@ public class Utils { + "..." + path.substring(path.length() - SHORTENED_PATH_LENGTH); } + + public static String filesystemSafe(String text) { + return text.replaceAll("[^a-zA-Z0-9.-]", "_") + .replaceAll("__", "_") + .replaceAll("_+$", ""); + } } \ No newline at end of file