Fix multipart Content-Type headers with both boundary and charset parameters (#1516)

* Fix multipart Content-Type headers with both boundary and charset parameters

* Improve code readability

* Add missing forward declaration

---------

Co-authored-by: Mathieu Gaillard <gaillard@adobe.com>
This commit is contained in:
Mathieu Gaillard 2023-03-08 20:57:17 -08:00 committed by GitHub
parent 9f7ae0737a
commit df74526f91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 2 deletions

View file

@ -1823,6 +1823,8 @@ std::string params_to_query_str(const Params &params);
void parse_query_text(const std::string &s, Params &params);
bool parse_multipart_boundary(const std::string &content_type, std::string &boundary);
bool parse_range_header(const std::string &s, Ranges &ranges);
int close_socket(socket_t sock);
@ -3888,9 +3890,12 @@ inline void parse_query_text(const std::string &s, Params &params) {
inline bool parse_multipart_boundary(const std::string &content_type,
std::string &boundary) {
auto pos = content_type.find("boundary=");
auto boundary_keyword = "boundary=";
auto pos = content_type.find(boundary_keyword);
if (pos == std::string::npos) { return false; }
boundary = content_type.substr(pos + 9);
auto end = content_type.find(';', pos);
auto beg = pos + strlen(boundary_keyword);
boundary = content_type.substr(beg, end - beg);
if (boundary.length() >= 2 && boundary.front() == '"' &&
boundary.back() == '"') {
boundary = boundary.substr(1, boundary.size() - 2);