[ 
https://issues.apache.org/jira/browse/FILEUPLOAD-208?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13736871#comment-13736871
 ] 

Jochen Wiedmann commented on FILEUPLOAD-208:
--------------------------------------------

I applied the following patch:

Index: src/main/java/org/apache/commons/fileupload/FileUploadBase.java
===================================================================
--- src/main/java/org/apache/commons/fileupload/FileUploadBase.java     
(revision 1513131)
By default, the requests character encoding is now used. Should be upwards 
compatible, as setHeaderEncoding() isn't actually referenced, so headerEncoding 
will be null anyways.

+++ src/main/java/org/apache/commons/fileupload/FileUploadBase.java     
(working copy)
@@ -980,9 +980,9 @@
                 };
             }
 
-            String charEncoding = headerEncoding;
+            String charEncoding = ctx.getCharacterEncoding();
             if (charEncoding == null) {
-                charEncoding = ctx.getCharacterEncoding();
+                charEncoding = headerEncoding;
             }
 
             boundary = getBoundary(contentType);

                
> CLONE - [fileupload] Use the ServletRequest encoding as default
> ---------------------------------------------------------------
>
>                 Key: FILEUPLOAD-208
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-208
>             Project: Commons FileUpload
>          Issue Type: Improvement
>    Affects Versions: 1.2.2
>         Environment: All supported environments.
>            Reporter: Fernando Ribeiro
>
> The fileupload package operates on a ServletRequest to conveniently extract 
> it's
> content. The ServletRequest.getCharacterEncoding() method "Returns the name of
> the character encoding used in the body of this request", and thus should be
> used as a default by the fileupload processing as well.
> Further, whether from the servlet request or an explicit set on the FileUpload
> instance, the encoding should propagate to the FileItem (again by default,
> unless it's overridden by a part content type header or explicit set).
> Currently, in order to have a UTF-8 request properly parsed, one must first 
> call
> request.setCharacterEncoding("UTF-8")
> then call
> diskFileUpload.setHeaderEncoding("UTF-8")
> and finally use
> fileItem.getString("UTF-8")
> There's no reason for this duplicity - if the first is set, the rest should
> propagate by default, unless explicitly overridden. This is a source for bugs
> and unneeded extra work (it took quite a while to figure these out, after
> examining the source code - this work can be saved for other developers, after
> all, that's what this package is for!).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to