X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FDownloadFile.java;h=8e04cf64f29bfa279a96343fc3f929f67415ec26;hb=359b1f6878f98127577b348b189fa01401971654;hp=1a3b76dae267abaaf7b1deb034e18c4c19aeca66;hpb=1bd5ba3b9f91e69517fa8a39665256f0badc408b;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java index 1a3b76da..8e04cf64 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java +++ b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java @@ -50,9 +50,15 @@ public class DownloadFile extends AppCompatDialogFragment { Bundle argumentsBundle = new Bundle(); String fileNameString; - if (!contentDisposition.isEmpty()) { // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending with the next `"`. + + // Parse `filename` from `contentDisposition`. + if (contentDisposition.contains("filename=\"")) { // The file name is contained in a string surrounded by `""`. fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10, contentDisposition.indexOf("\"", contentDisposition.indexOf("filename=\"") + 10)); - } else { // `contentDisposition` is empty, so use the last path segment of the URL as the file name. + } else if (contentDisposition.contains("filename=") && ((contentDisposition.indexOf(";", contentDisposition.indexOf("filename=") + 9)) > 0 )) { // The file name is contained in a string beginning with `filename=` and ending with `;`. + fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=") + 9, contentDisposition.indexOf(";", contentDisposition.indexOf("filename=") + 9)); + } else if (contentDisposition.contains("filename=")) { // The file name is contained in a string beginning with `filename=` and proceeding to the end of `contentDisposition`. + fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=") + 9, contentDisposition.length()); + } else { // `contentDisposition` does not contain the filename, so use the last path segment of the URL. Uri downloadUri = Uri.parse(urlString); fileNameString = downloadUri.getLastPathSegment(); }