mirror of
https://github.com/actix/actix-web.git
synced 2024-06-13 02:39:32 +00:00
Properly handle newlines in filenames
This commit is contained in:
parent
1e54f87366
commit
92725342fd
|
@ -24,7 +24,6 @@ use bitflags::bitflags;
|
|||
use derive_more::{Deref, DerefMut};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use mime::Mime;
|
||||
use mime_guess::from_path;
|
||||
|
||||
use crate::{encoding::equiv_utf8_text, range::HttpRange};
|
||||
|
||||
|
@ -128,7 +127,7 @@ impl NamedFile {
|
|||
}
|
||||
};
|
||||
|
||||
let ct = from_path(&path).first_or_octet_stream();
|
||||
let ct = mime_guess::from_path(&path).first_or_octet_stream();
|
||||
|
||||
let disposition = match ct.type_() {
|
||||
mime::IMAGE | mime::TEXT | mime::AUDIO | mime::VIDEO => DispositionType::Inline,
|
||||
|
@ -140,7 +139,9 @@ impl NamedFile {
|
|||
_ => DispositionType::Attachment,
|
||||
};
|
||||
|
||||
let mut parameters = vec![DispositionParam::Filename(String::from(filename.as_ref()))];
|
||||
// Replace newlines in filenames which could occur on some filesystems.
|
||||
let filename_s = filename.replace('\n', "%0A");
|
||||
let mut parameters = vec![DispositionParam::Filename(filename_s)];
|
||||
|
||||
if !filename.is_ascii() {
|
||||
parameters.push(DispositionParam::FilenameExt(ExtendedValue {
|
||||
|
|
Loading…
Reference in a new issue