Bug 54984

Summary: multipart/form-data is not always read with correct encoding
Product: Tomcat 7 Reporter: Per Holmberg <holmis83>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.40   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Multipart demo war
Multipart demo source

Description Per Holmberg 2013-05-16 11:15:20 UTC
The bug occurs when form data is posted as multipart/form-data and using Servlet 3 API to get posted files.
In a servlet, if we set the encoding:

request.setCharacterEncoding("UTF-8");

Then invoke:

request.getParts()

And then invoke:

String text = request.getParameter("sometextfield");

UTF-8 characters in the text have been garbled.

Order of method calls are significant, if a getParameter is called before getParts, the correct encoding will be used.
However, the order which you invoke the methods should not matter.
Comment 1 Christopher Schultz 2013-05-21 20:15:35 UTC
Can you post a simple test-case as a WAR (including source) to reproduce this?
Comment 2 Per Holmberg 2013-05-22 11:36:44 UTC
Created attachment 30311 [details]
Multipart demo war
Comment 3 Per Holmberg 2013-05-22 11:42:32 UTC
Created attachment 30312 [details]
Multipart demo source
Comment 4 Violeta Georgieva 2013-05-26 20:05:28 UTC
Thanks for the report.
Fixed in trunk and 7.0.x and will be included in 7.0.41 onwards.