Accept a language tag in a multipart filename* parameter (#2704)

* Accept a language tag in a multipart filename* parameter

RFC 8187 writes an ext-value as charset'[language]'value-chars. The parser
only took the "UTF-8''" form, so filename*=UTF-8'en'%41.txt made the whole
multipart body invalid and the request got 400. Skip the language tag and
decode the value as before.

* Shorten the comments and close the connection in the new test

Without Connection: close the server kept the connection open, so the
test waited for the 1-second read timeout of send_request().

---------

Co-authored-by: yhirose <yuji.hirose.bug@gmail.com>
This commit is contained in:
Leng Niuandyhirose authored and GitHub committed 2026-12-02 00:21:30 -05:00
1 parent 012a9871b1
commit 852a66bcec
2 files changed
+52 -5

No files matched your search

+8 -5
View File
@@ -10516,14 +10516,17 @@ public:
it = params.find("filename*");
if (it != params.end()) {
// RFC 5987: only UTF-8 encoding is allowed
// RFC 8187: UTF-8'[language]'value-chars
const auto &val = it->second;
constexpr const char utf8_prefix[] = "UTF-8''";
constexpr const char utf8_prefix[] = "UTF-8'";
constexpr size_t prefix_len = str_len(utf8_prefix);
if (val.size() > prefix_len &&
start_with_case_ignore(val, utf8_prefix)) {
const auto value_pos = start_with_case_ignore(val, utf8_prefix)
? val.find('\'', prefix_len)
: std::string::npos;
if (value_pos != std::string::npos &&
value_pos + 1 < val.size()) {
file_.filename = decode_path_component(
val.substr(prefix_len)); // override...
val.substr(value_pos + 1)); // override...
} else {
is_valid_ = false;
return false;