Просмотр исходного кода

Implicit "text/plain" when MIME type starts with ";"

Simon Sapin 8 лет назад
Родитель
Сommit
14c82067d0
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      src/lib.rs

+ 8 - 1
src/lib.rs

@@ -112,14 +112,21 @@ fn parse_header(from_colon_to_comma: &str) -> (mime::Mime, bool) {
     let input = from_colon_to_comma.chars()
         .filter(|&c| !matches!(c, '\t' | '\n' | '\r'))  // Removed by the URL parser
         .collect::<String>();
+    let mut string;
 
     let input = input.trim_matches(' ');
 
-    let (input, base64) = match without_base64_suffix(input) {
+    let (mut input, base64) = match without_base64_suffix(input) {
         Some(s) => (s, true),
         None => (input, false),
     };
 
+    if input.starts_with(';') {
+        string = String::from("text/plain");
+        string.push_str(input);
+        input = &*string;
+    }
+
     // FIXME: does Mime::from_str match the MIME Sniffing Standard’s parsing algorithm?
     // <https://mimesniff.spec.whatwg.org/#parse-a-mime-type>
     let mime_type = input.parse()