You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Jacopo Cappellato <ja...@hotwaxsystems.com> on 2016/09/09 13:33:37 UTC
Fixing the way OFBiz deal with character encoding of http requests
In ContextFilter, the character encoding (aka charset) of every http
*request* object is set using the WebAppUtil.setCharacterEncoding(...)
method (see its logic here [*]).
It is wrong to override the character encoding if already specified by the
http request: in fact it doesn't make any sense to try to decode an http
request, whose body content is encoded for example with ISO-8859-1, using
the OFBiz system's default of UTF-8.
I propose instead to set the character encoding to the system default (e.g.
UTF-8) if and only if it is not set already by the client.
Any comments before I commit this change?
Kind regards,
Jacopo
[*] the logic of WebAppUtil.setCharacterEncoding(...):
public static void setCharacterEncoding(ServletRequest request) {
String charset = request.getServletContext().getInitParameter("charset");
if (UtilValidate.isEmpty(charset)) charset = request.getCharacterEncoding();
if (UtilValidate.isEmpty(charset)) charset = "UTF-8";
if (!"none".equals(charset)) {
request.setCharacterEncoding(charset);
}
}
Re: Fixing the way OFBiz deal with character encoding of http requests
Posted by Jacopo Cappellato <ja...@hotwaxsystems.com>.
Committed in rev. 1760528
Jacopo
On Fri, Sep 9, 2016 at 3:33 PM, Jacopo Cappellato <
jacopo.cappellato@hotwaxsystems.com> wrote:
> In ContextFilter, the character encoding (aka charset) of every http
> *request* object is set using the WebAppUtil.setCharacterEncoding(...)
> method (see its logic here [*]).
>
> It is wrong to override the character encoding if already specified by the
> http request: in fact it doesn't make any sense to try to decode an http
> request, whose body content is encoded for example with ISO-8859-1, using
> the OFBiz system's default of UTF-8.
>
> I propose instead to set the character encoding to the system default
> (e.g. UTF-8) if and only if it is not set already by the client.
>
> Any comments before I commit this change?
>
> Kind regards,
>
> Jacopo
>
> [*] the logic of WebAppUtil.setCharacterEncoding(...):
>
> public static void setCharacterEncoding(ServletRequest request) {
> String charset = request.getServletContext().getInitParameter("charset");
> if (UtilValidate.isEmpty(charset)) charset = request.getCharacterEncoding();
> if (UtilValidate.isEmpty(charset)) charset = "UTF-8";
> if (!"none".equals(charset)) {
> request.setCharacterEncoding(charset);
> }
> }
>
>
>