From 76cbcc8b96b1a3ddc8ac3e89e90b3bc6b0d3071d Mon Sep 17 00:00:00 2001 From: Rob Kooper Date: Fri, 22 Apr 2022 14:39:20 -0500 Subject: [PATCH] fix/cleanup filename --- CHANGELOG.md | 5 +++++ app/util/FileUtils.scala | 39 +++++++++++---------------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b23d0aae..4b0bc4a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed +- When downloading a file with a `'` in the name it would save the file as blob + ## 1.20.1 - 2022-04-04 ### Fixed diff --git a/app/util/FileUtils.scala b/app/util/FileUtils.scala index 1d66d2f93..fd5790f1d 100644 --- a/app/util/FileUtils.scala +++ b/app/util/FileUtils.scala @@ -856,37 +856,20 @@ object FileUtils { //Download CONTENT-DISPOSITION encoding // def encodeAttachment(filename: String, userAgent: String) : String = { - val filenameStar = if (userAgent.indexOf("MSIE") > -1) { - URLEncoder.encode(filename, "UTF-8") - } else if (userAgent.indexOf("Edge") > -1){ - MimeUtility.encodeText(filename - .replaceAll(",","%2C") - .replaceAll("\"","%22") - .replaceAll("/","%2F") - .replaceAll("=","%3D") - .replaceAll("&","%26") - .replaceAll(":","%3A") - .replaceAll(";","%3B") - .replaceAll("\\?","%3F") - .replaceAll("\\*","%2A") + val filenameStar = MimeUtility.encodeText(filename + .replaceAll("%","%25") + .replaceAll(" ","%20") + .replaceAll("\"","%22") + .replaceAll("'","%27") + .replaceAll(",","%2C") + .replaceAll("/","%2F") + .replaceAll("=","%3D") + .replaceAll(":","%3A") + .replaceAll(";","%3B") + .replaceAll("\\*","%2A") ,"utf-8","Q") - } else { - MimeUtility.encodeText(filename - .replaceAll("%","%25") - .replaceAll(" ","%20") - .replaceAll("\"","%22") - .replaceAll(",","%2C") - .replaceAll("/","%2F") - .replaceAll("=","%3D") - .replaceAll(":","%3A") - .replaceAll(";","%3B") - .replaceAll("\\*","%2A") - ,"utf-8","Q") - } - Logger.debug(userAgent + ": " + filenameStar) //Return the complete attachment header info "attachment; filename*=UTF-8''" + filenameStar } - }