Fixing the way OFBiz deal with character encoding of http requests

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fixing the way OFBiz deal with character encoding of http requests

Jacopo Cappellato-5
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);
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Fixing the way OFBiz deal with character encoding of http requests

Jacopo Cappellato-5
Committed in rev. 1760528

Jacopo

On Fri, Sep 9, 2016 at 3:33 PM, Jacopo Cappellato <
[hidden email]> 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);
>     }
> }
>
>
>