From 5b78ba0266e3a7a415c28028d522b3ebe3797650 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 28 Oct 2018 08:07:13 -0400 Subject: [PATCH] DownloadFileThread now removes all illegal chars from filenames before trying to write the file to disk --- .../com/rarchives/ripme/ripper/DownloadFileThread.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java index 77a59a3e..54619a28 100644 --- a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java +++ b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java @@ -62,12 +62,19 @@ class DownloadFileThread extends Thread { this.cookies = cookies; } + public File sanitizeSaveAs(File fileToSan) { + String fileName = fileToSan.getName().replaceAll("[\\\\/:*?\"<>|]", "_"); + return new File(saveAs.getParentFile().getAbsolutePath() + File.separator + fileName); + } + /** * Attempts to download the file. Retries as needed. * Notifies observers upon completion/error/warn. */ public void run() { + // First thing we make sure the file name doesn't have any illegal chars in it + saveAs = sanitizeSaveAs(saveAs); long fileSize = 0; int bytesTotal = 0; int bytesDownloaded = 0;