MultiPartParser skips fields when sending empty files
Describe the bug
MultiPartParser does not parse the request body correctly when an empty file is transmitted as the first member of the body.
To Reproduce
- Create a POST Endpoint that reads out the multipart body.
- Create a sample HTML page that has a
<input type="file" />as the first input in a form - Add more
of whatever types - Dispatch the form without supplying a file
- Endpoint reads out no parameters
Expected behavior
The MultiPartParser should return the request body with the parameters set.
Currently, MultiPartParser::parse returns -1 with an empty <input type="file" />
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Linux
- Browser: Firefox
- Version: 133.0.3
The bug also occurs on chrome.
Additional context
The implementation of MultiPartParser::parseEntity is faulty in that it expects each multi-part file to have a filename.
When sending a form that has no filename set, the parser stops parsing subsequent fields.
The offending code is the conditional at MultiPart.cc:214
Here's an excerpt of the failing request body:
-----------------------------105238891342303886541107959621
Content-Disposition: form-data; name="cover"; filename=""
Content-Type: application/octet-stream
-----------------------------105238891342303886541107959621
Content-Disposition: form-data; name="abstract"
test
-----------------------------105238891342303886541107959621
Content-Disposition: form-data; name="language"
test
-----------------------------105238891342303886541107959621--