summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLewis Diamond <lewis@jogogo.co>2019-02-10 10:52:18 -0500
committerKartikaya Gupta (kats) <staktrace@users.noreply.github.com>2019-02-10 11:27:37 -0500
commit8ad2f47d4e9712163e98c05bd1a3b9891b075642 (patch)
treed795a2d010e64871c970e3e93b752a0132803815
parent4247ebfbf25f2abdbba75853e159955cc9d5d5ef (diff)
downloadmailparse-8ad2f47d4e9712163e98c05bd1a3b9891b075642.tar.gz
mailparse-8ad2f47d4e9712163e98c05bd1a3b9891b075642.tar.xz
Fix panic when encountering param content with new line
-rw-r--r--src/lib.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 51ea515..ec3905b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -815,7 +815,7 @@ fn parse_param_content(content: &str) -> ParamContent {
kv.find('=').map(|idx| {
let key = kv[0..idx].trim().to_lowercase();
let mut value = kv[idx + 1..].trim();
- if value.starts_with('"') && value.ends_with('"') {
+ if value.starts_with('"') && value.ends_with('"') && value.len() > 1 {
value = &value[1..value.len() - 1];
}
(key, value.to_string())
@@ -1208,4 +1208,10 @@ mod tests {
let test = "\u{FFFD}\u{FFFD}\u{FFFD}\u{FFFD}\u{FFFD}\u{FFFD}";
assert!(is_boundary(test, Some(8)));
}
+
+ #[test]
+ fn test_dont_panic_for_value_with_new_lines() {
+ let parsed = parse_param_content(r#"Content-Type: application/octet-stream; name=""#);
+ assert_eq!(parsed.params["name"], "\"");
+ }
}