diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java index 0a0fa306..4aabe559 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java @@ -6,7 +6,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Date; import java.util.List; import java.util.regex.Matcher; @@ -287,9 +286,9 @@ public class RedditRipper extends AlbumRipper { ).renderFormatted(); try { - saveFileAs = Paths.get(workingDir + saveFileAs = Utils.getPath(workingDir + "/" - + id + "_" + title.replaceAll("[\\\\/:*?\"<>|]", "") + + id + "_" + title + ".html"); OutputStream out = Files.newOutputStream(saveFileAs); out.write(html.getBytes()); @@ -406,7 +405,7 @@ public class RedditRipper extends AlbumRipper { // It's from reddituploads. Assume .jpg extension. String savePath = this.workingDir + "/"; savePath += id + "-" + m.group(1) + title + ".jpg"; - addURLToDownload(urls.get(0), Paths.get(savePath)); + addURLToDownload(urls.get(0), Utils.getPath(savePath)); } if (url.contains("v.redd.it")) { String savePath = this.workingDir + "/"; @@ -414,7 +413,7 @@ public class RedditRipper extends AlbumRipper { URL urlToDownload = parseRedditVideoMPD(urls.get(0).toExternalForm()); if (urlToDownload != null) { LOGGER.info("url: " + urlToDownload + " file: " + savePath); - addURLToDownload(urlToDownload, Paths.get(savePath)); + addURLToDownload(urlToDownload, Utils.getPath(savePath)); } } else { diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 3038eacc..97b2f752 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -830,8 +830,12 @@ public class Utils { return Files.exists(folder.resolve(filename)); } + public static Path getPath(String pathToSanitize) { + return Paths.get(sanitizeSaveAs(pathToSanitize)); + } + public static String sanitizeSaveAs(String fileNameToSan) { - return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_"); + return fileNameToSan.replaceAll("[\\\\:*?\"<>|]", "_"); } public static Path shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {