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

Match Content-Disposition parameter names case-insensitively (#2698)

parse_disposition_params stored parameter names as they arrived, while FormDataParser looks up "name", "filename" and "filename*" in lower case. A part with NAME= was rejected with 400, and one with FILENAME*= was silently treated as a plain field. Parameter names are case-insensitive (RFC 2045 section 5.1), so the names are now lowercased when stored, as extract_media_type already does for Content-Type. Values keep their case.
Eminy 4 дней назад
Родитель
Сommit
d5befb4326
2 измененных файлов с 6 добавлено и 1 удалено
  1. 3 1
      httplib.h
  2. 3 0
      test/test.cc

+ 3 - 1
httplib.h

@@ -10180,8 +10180,10 @@ inline void parse_disposition_params(const std::string &s, Params &params) {
         std::string val;
         divide_param_pair(b, e, key, val);
 
+        // Parameter names are case-insensitive (RFC 2045 §5.1)
         if (!key.empty()) {
-          params.emplace(trim_double_quotes_copy(key), unquote_param(val));
+          params.emplace(case_ignore::to_lower(trim_double_quotes_copy(key)),
+                         unquote_param(val));
         }
       });
 }

+ 3 - 0
test/test.cc

@@ -2093,6 +2093,9 @@ TEST(ParseDispositionParamsTest, QuotedValues) {
   } cases[] = {
       {"name=\"file1\"; filename=\"a.txt\"",
        {{"name", "file1"}, {"filename", "a.txt"}}},
+      // MIME parameter names are case-insensitive, but their values are not.
+      {"NaMe=\"Upload\"; FiLeNaMe=\"Report.TXT\"",
+       {{"name", "Upload"}, {"filename", "Report.TXT"}}},
       // Whitespace around '=' and ';' is still trimmed
       {"name=\"file2\" ;filename = \"a.html\"",
        {{"name", "file2"}, {"filename", "a.html"}}},