Skip to content

Commit 8ba7532

Browse files
authored
Merge pull request #353 from clowder-framework/fix-download-name
fix/cleanup filename
2 parents 2ec13db + c3d6bc0 commit 8ba7532

2 files changed

Lines changed: 13 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Fixed
1111
- swagger lint action
12-
12+
- When downloading a file with a `'` in the name it would save the file as blob
13+
-
1314
### Changed
1415
- Changed `Enabled By SuperAdmin` to read `Enabled by Server Admin` [#344](https://github.com/clowder-framework/clowder/issues/344)
1516

app/util/FileUtils.scala

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -856,37 +856,20 @@ object FileUtils {
856856
//Download CONTENT-DISPOSITION encoding
857857
//
858858
def encodeAttachment(filename: String, userAgent: String) : String = {
859-
val filenameStar = if (userAgent.indexOf("MSIE") > -1) {
860-
URLEncoder.encode(filename, "UTF-8")
861-
} else if (userAgent.indexOf("Edge") > -1){
862-
MimeUtility.encodeText(filename
863-
.replaceAll(",","%2C")
864-
.replaceAll("\"","%22")
865-
.replaceAll("/","%2F")
866-
.replaceAll("=","%3D")
867-
.replaceAll("&","%26")
868-
.replaceAll(":","%3A")
869-
.replaceAll(";","%3B")
870-
.replaceAll("\\?","%3F")
871-
.replaceAll("\\*","%2A")
859+
val filenameStar = MimeUtility.encodeText(filename
860+
.replaceAll("%","%25")
861+
.replaceAll(" ","%20")
862+
.replaceAll("\"","%22")
863+
.replaceAll("'","%27")
864+
.replaceAll(",","%2C")
865+
.replaceAll("/","%2F")
866+
.replaceAll("=","%3D")
867+
.replaceAll(":","%3A")
868+
.replaceAll(";","%3B")
869+
.replaceAll("\\*","%2A")
872870
,"utf-8","Q")
873-
} else {
874-
MimeUtility.encodeText(filename
875-
.replaceAll("%","%25")
876-
.replaceAll(" ","%20")
877-
.replaceAll("\"","%22")
878-
.replaceAll(",","%2C")
879-
.replaceAll("/","%2F")
880-
.replaceAll("=","%3D")
881-
.replaceAll(":","%3A")
882-
.replaceAll(";","%3B")
883-
.replaceAll("\\*","%2A")
884-
,"utf-8","Q")
885-
}
886-
Logger.debug(userAgent + ": " + filenameStar)
887871

888872
//Return the complete attachment header info
889873
"attachment; filename*=UTF-8''" + filenameStar
890874
}
891-
892875
}

0 commit comments

Comments
 (0)