The code in MultipartUrlConfig.java that currently handles the parsing of multipart/form-data request is vunerable. If a multipart section contains any header except "Content-Disposition: form-data;", for example a "Content-Type: text/plain", the parsing uses everything after the first headerline as the value of the form parameter. The same problem is present for file uploads I suggest to add support for having any headers in the multipar sections.
Created attachment 19988 [details] Suggested patch This suggested patch uses regular expression to find values for headers we need during parsing of multipart sections. Headers which are not used, are ignored. This patch also sets the value for the parameter correctly. This patch also adds a number of unit tests for parsing of http posting of multipart/form-data and file uploads.
Created attachment 19989 [details] Updated patch Same patch as above, but add if test to only set file parameters in sampler, if a file name is present. If you have a form with both fields and file upload fields, then there will be multipart section for the the file upload fields, with filename="" if you do not specify a file for it. It is only confusing to set the mime type and file field values in the sampler in this case.
Created attachment 19990 [details] Updated patch This updated patch adds the private method addNonEncodedArgument, so that in the sampler that is put into the test plan, the "Encode?" checkbox is off. A multipart/form-data request that is sent by Jmeter does not use the "Encode?" setting at all, because multipart/form-data values are not url encoded. So I think it is less likely to confuse the user if the checkbox is always off.
The test case testPostMultipartFormData() fails the checkArgument() tests - the arg.isAlwaysEncoded() comparisons fail. I'm not sure if this is a test error or a bug ...
Created attachment 19995 [details] Updated patch I'm sorry, but I forgot to update the unit tests after the last minute change to add the private method addNonEncodedArgument. I have now updated the unit tests, because the "Encode?" will always be false now, for multipart/form-data requests. I have also included an unrelated change to the TestHTTPSamplersAgainstHttpMirrorServer, which was lost when patches where applied for it yesterday.
Thanks - applied to SVN in r530547
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1914