From d5befb43264031d5347a96321b3a42457c992c47 Mon Sep 17 00:00:00 2001 From: Eminy <57416756+emincan2000@users.noreply.github.com> Date: Fri, 27 Nov 2026 03:02:31 +0300 Subject: [PATCH] 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. --- httplib.h | 4 +++- test/test.cc | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index fcf01fb8..4eb2b206 100644 --- a/httplib.h +++ b/httplib.h @@ -10180,8 +10180,10 @@ inline void parse_disposition_params(const std::string &s, Params ¶ms) { 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)); } }); } diff --git a/test/test.cc b/test/test.cc index fca86ea9..52224f39 100644 --- a/test/test.cc +++ b/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"}}},