mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-27 20:58:28 +00:00
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.
This commit is contained in:
1 parent
bb00fece7c
commit
d5befb4326
2 files changed
+6
-1
No files matched your search
@@ -10180,8 +10180,10 @@ inline void parse_disposition_params(const std::string &s, Params ¶ms) {
|
|||||||
std::string val;
|
std::string val;
|
||||||
divide_param_pair(b, e, key, val);
|
divide_param_pair(b, e, key, val);
|
||||||
|
|
||||||
|
// Parameter names are case-insensitive (RFC 2045 §5.1)
|
||||||
if (!key.empty()) {
|
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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2093,6 +2093,9 @@ TEST(ParseDispositionParamsTest, QuotedValues) {
|
|||||||
} cases[] = {
|
} cases[] = {
|
||||||
{"name=\"file1\"; filename=\"a.txt\"",
|
{"name=\"file1\"; filename=\"a.txt\"",
|
||||||
{{"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
|
// Whitespace around '=' and ';' is still trimmed
|
||||||
{"name=\"file2\" ;filename = \"a.html\"",
|
{"name=\"file2\" ;filename = \"a.html\"",
|
||||||
{{"name", "file2"}, {"filename", "a.html"}}},
|
{{"name", "file2"}, {"filename", "a.html"}}},
|
||||||
|
|||||||
Reference in new issue
Block a user