You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Hudson (Commented) (JIRA)" <ji...@apache.org> on 2012/04/11 21:03:18 UTC

[jira] [Commented] (WW-3059) Decoding of parameters sent with XMLHttpRequest

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

Hudson commented on WW-3059:
----------------------------

Integrated in Struts2 #454 (See [https://builds.apache.org/job/Struts2/454/])
    WW-3059 Changes logic to set encoding for XMLHttpRequest type (Revision 1324870)

     Result = SUCCESS
lukaszlenart : 
Files : 
* /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
* /struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java

                
> Decoding of parameters sent with XMLHttpRequest
> -----------------------------------------------
>
>                 Key: WW-3059
>                 URL: https://issues.apache.org/jira/browse/WW-3059
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Dispatch Filter
>    Affects Versions: 2.0.14, 2.1.6
>            Reporter: Miguel Diaz
>            Assignee: Lukasz Lenart
>             Fix For: 2.3.3
>
>
> org.apache.struts2.dispatcher.Dispatcher uses the configured default encoding (in the struts properties, with the "struts.i18n.encoding" key) when decoding received parameters.
> If a request is sent with XMLHttpRequest, the parameters will allways be encoded in UTF-8, as specified in http://www.w3.org/TR/XMLHttpRequest/#send. This matches current browser behaviour (at least for IE7 and FF3).
> If one has configured, say, ISO-8859-1	as the default encoding, the parameters will be decoded with the wrong charset.
> This may be fixed checking if the request was sent using XMLHttpRequest. All the major JavaScript libraries (jQuery, Dojo...) as well as other languages and frameworks (Ruby on Rails, the Zend Framework and CakePHP) use the X-Requested-With header when sending request with XMLHttpRequest.
> Assuming that the client side is using that technique, the fix is rather simple: in org.apache.struts2.dispatcher.Dispatcher.prepare(), check if the request was sent by XMLHttpRequest and in that case set the UTF-8 character encoding regardless of the default encoding:
> if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With")))
>   encoding = "UTF-8";

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira