1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 08:57:00 +02:00

actix-files: fix handling linebreaks in filenames (#3237)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Dialga
2024-01-10 16:56:15 +13:00
committed by GitHub
parent ac04d80d8e
commit fcfc727295
3 changed files with 13 additions and 5 deletions

View File

@@ -139,8 +139,12 @@ impl NamedFile {
_ => DispositionType::Attachment,
};
// Replace newlines in filenames which could occur on some filesystems.
let filename_s = filename.replace('\n', "%0A");
// replace special characters in filenames which could occur on some filesystems
let filename_s = filename
.replace('\n', "%0A") // \n line break
.replace('\x0B', "%0B") // \v vertical tab
.replace('\x0C', "%0C") // \f form feed
.replace('\r', "%0D"); // \r carriage return
let mut parameters = vec![DispositionParam::Filename(filename_s)];
if !filename.is_ascii() {