Multipart upload and text field encoding problems and a suggested fix #43
ipuschnig
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have successfully upgraded an old Struts 1.3 project to the 1.5 version here, without significant problems.
However, in tests we found that there are subtle changes in how struts works together with the new apache commons fileupload2. In particular, text fields submitted in a multipart/form-data request would have the wrong encoding.
We tracked down the problem to the class org.apache.struts.upload.CommonsMultipartRequestHandler.
This class uses the method getTextValue(HttpServletRequest, FileItem<?>), lines 544+. The first thing the method does is to check if the provided FileItem is a DiskFileItem. That class from commons fileupload2 returns default CharSet ISO-8859-1 now. In the old version it returned a string which was null usually. As a result, getTextValue() would now use the ISO-8859-1 charset to parse the text value, instead of the request character encoding.
So we made a slight modification: We require a system property to be set before the check for DiskFileItem is made (and we don't set that property). So the request character encoding is used every time. By setting the property we could enable the original behaviour again:
Before:
if (item instanceof DiskFileItem) { encoding = ((DiskFileItem)item).getCharset(); log.debug("DiskFileItem.getCharset=[{}]", encoding); }
With our modification:
if (item instanceof DiskFileItem && System.getProperty("multipart-upload.use-default-charset") != null) { encoding = ((DiskFileItem)item).getCharset(); log.debug("DiskFileItem.getCharset=[{}]", encoding); }
I hope this helps others who run into the encoding problems mentioned above.
Beta Was this translation helpful? Give feedback.
All reactions