Fix Content-Disposition header for non-latin characters (#1)

This commit is contained in:
Arlo (Hyena) 2019-01-19 14:49:26 +00:00 committed by Gitea
parent 2e23cdecfb
commit 32fbd71d03
3 changed files with 14 additions and 51 deletions

View file

@ -1,10 +1,10 @@
[package]
name = "actix-form-data"
description = "Multipart Form Data for Actix Web"
version = "0.3.1"
version = "0.3.2"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.cloud/asonix/actix-form-data.git"
repository = "https://git.asonix.dog/asonix/actix-form-data.git"
readme = "README.md"
keywords = ["actix", "form-data", "multipart", "async"]
@ -12,7 +12,7 @@ keywords = ["actix", "form-data", "multipart", "async"]
name = "form_data"
[dependencies]
actix-web = "0.7.0"
actix-web = "0.7.15"
bytes = "0.4.7"
failure = "0.1"
futures = "0.1.21"

View file

@ -11,8 +11,8 @@ Add it to your dependencies.
# Cargo.toml
[dependencies]
actix-web = "0.7.0"
actix-form-data = "0.3.1"
actix-web = "0.7.15"
actix-form-data = "0.3.2"
```
Require it in your project.

View file

@ -35,7 +35,6 @@ use futures::{
Future, Stream,
};
use futures_fs::FsPool;
use http::header::CONTENT_DISPOSITION;
use super::FilenameGenerator;
use error::Error;
@ -93,50 +92,17 @@ fn parse_multipart_name(name: String) -> Result<Vec<NamePart>, Error> {
})
}
fn parse_content_disposition<S>(field: &multipart::Field<S>) -> Result<ContentDisposition, Error>
fn parse_content_disposition<S>(field: &multipart::Field<S>) -> ContentDisposition
where
S: Stream<Item = Bytes, Error = PayloadError>,
{
let content_disposition = if let Some(cd) = field.headers().get(CONTENT_DISPOSITION) {
cd
} else {
return Err(Error::ContentDisposition);
};
let content_disposition = if let Ok(cd) = content_disposition.to_str() {
cd
} else {
return Err(Error::ContentDisposition);
};
Ok(content_disposition
.split(';')
.skip(1)
.filter_map(|section| {
let mut parts = section.splitn(2, '=');
let key = if let Some(key) = parts.next() {
key.trim()
} else {
return None;
};
let val = if let Some(val) = parts.next() {
val.trim()
} else {
return None;
};
Some((key, val.trim_matches('"')))
})
.fold(ContentDisposition::empty(), |mut acc, (key, val)| {
if key == "name" {
acc.name = Some(val.to_owned());
} else if key == "filename" {
acc.filename = Some(val.to_owned());
}
acc
}))
match field.content_disposition() {
Some(x) => ContentDisposition {
name: x.get_name().map(|v| v.to_string()),
filename: x.get_filename().map(|v| v.to_string()),
},
None => ContentDisposition::empty(),
}
}
#[cfg(unix)]
@ -288,10 +254,7 @@ fn handle_stream_field<S>(
where
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
{
let content_disposition = match parse_content_disposition(&field) {
Ok(cd) => cd,
Err(e) => return Box::new(result(Err(e))),
};
let content_disposition = parse_content_disposition(&field);
let name = match content_disposition.name {
Some(name) => name,