Decoding of parameters sent with XMLHttpRequest
-----------------------------------------------

                 Key: WW-3059
                 URL: https://issues.apache.org/struts/browse/WW-3059
             Project: Struts 2
          Issue Type: Bug
          Components: Dispatch Filter
    Affects Versions: 2.1.6, 2.0.14
            Reporter: Miguel Diaz


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.
-
You can reply to this email to add a comment to the issue online.

Reply via email to