rwf2 / multer

An async parser for multipart/form-data content-type in Rust
MIT License
156 stars 35 forks source link

Unable to support utf8 file name #12

Closed sunli829 closed 4 years ago

sunli829 commented 4 years ago

Filename: 你好.txt

curl 'localhost:8000' --form 'operations={"query": "mutation ($file: Upload!) { singleUpload(file: $file) { id } }","variables": { "file": null }}' --form 'map={ "0": ["variables.file"] }' --form '0=@你好.txt' 
rousan commented 4 years ago

can you share the error messages?

sunli829 commented 4 years ago
impl ContentDisposition {
    pub fn parse(headers: &HeaderMap) -> ContentDisposition {
        let content_disposition = headers
            .get(header::CONTENT_DISPOSITION)
            .and_then(|val| val.to_str().ok());  // HeaderValue::to_str will make an error, maybe you should just parse bytes?

        let field_name = content_disposition
            .and_then(|val| constants::CONTENT_DISPOSITION_FIELD_NAME_RE.captures(val))
            .and_then(|cap| cap.get(1))
            .map(|m| m.as_str().to_owned());

        let file_name = content_disposition
            .and_then(|val| constants::CONTENT_DISPOSITION_FILE_NAME_RE.captures(val))
            .and_then(|cap| cap.get(1))
            .map(|m| m.as_str().to_owned());

        ContentDisposition { field_name, file_name }
    }
}
rousan commented 4 years ago

Okay, let me check.

sunli829 commented 4 years ago

Thank you. 😀

rousan commented 4 years ago

Hey @sunli829 , I pushed the fix to feature/utf8-content-disposition branch. Can you please test it and let me know if it's working and then I will make a release,

[dependencies]
multer = { git = "https://github.com/rousan/multer-rs", branch = "feature/utf8-content-disposition" }
sunli829 commented 4 years ago

Thank you. I'll test it tomorrow morning. 😀

sunli829 commented 4 years ago

It's working very well now. Thank you very much! 😁

rousan commented 4 years ago

Released v1.2.1.