Skip to content

Conversation

blunchboxx
Copy link

Modified parse_body in multipart.h to support multipart form data without trailing CRLF as allowed by RFC 2046.

Cleaned up and commented code. Moved final_delim declaration outside loop and updated while loop condition to check state of final_delim instead.
@blunchboxx
Copy link
Author

Commit fixes #1040

{
std::string delimiter = dd + boundary;
std::string normal_delim = dd + boundary;
std::string final_delim = normal_delim + dd; // Create final delimiter to check against
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these strings are const or constexpr

if (found == std::string::npos)
// Find next regular and final delimiter
size_t next_normal = body.find(normal_delim);
size_t next_final = body.find(final_delim);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not very effective as next_final is always one position after next_normal or not found.
So it should be sufficient to check for dd after the normal delimiter instead of do a find again over the complete string.

Copy link
Member

@gittiver gittiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See code comments on algorithm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multipart parsing fails when final boundary lacks CRLF, contrary to RFC 2046

2 participants