Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-1569

AjaxButton break form data when IRequestSettings.#getResponseRequestEncoding is not UTF-8.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3.3
    • 1.3.4, 1.4-M2
    • wicket
    • None

    Description

      The AjaxButton encode all of input string by 'encodeUrlComponent()' JavaScript function at Wicket.Form.encode. The function encode the input string always by UTF-8 (it's a specification of ECMAScript), but WicketFilter always decode it by the encoding defined by the IRequestSettings#setResponseRequestEncoding() method.

      So if the response encoding is not UTF-8, all the input data will be broken at the decoding time. As a workaround, we can avoid the problem by setting the output encoding to "UTF-8". But many web sites is using other encodings than UTF-8. For example, people often use "Shift_JIS" encoding for web site in Japan(It is a most popular encoding in Japan).

      To fix this problem, I think, you need to change WicketFilter class and check request headers when you decode input data. If the request has a 'wicket-ajax' header and the value is 'true', you need decode the posted data by 'UTF-8'. Otherwise decode them by the encoding defined by IRequestSettings#setResponseRequestEncoding();

      The changed code is below. It is a modification code at line 286 of WicketFilter class of Wicket 1.3.3.
      ======================
      if (servletRequest.getCharacterEncoding() == null) {
      try {
      // It this request is a wicket-ajax request, we need decode the
      // request always by UTF-8, because the request data is encoded by
      // encodeUrlComponent() JavaScript function, which always encode data
      // by UTF-8.
      String wicketAjaxHeader = servletRequest.getHeader("wicket-ajax");
      if(wicketAjaxHeader != null && wicketAjaxHeader.equals("true"))

      { servletRequest.setCharacterEncoding("UTF-8"); }

      else

      { // The encoding defined by the wicket settings is used to // encode the responses. Thus, it is reasonable to assume // the request has the same encoding. This is especially // important for forms and form parameters. servletRequest.setCharacterEncoding(webApplication.getRequestCycleSettings().getResponseRequestEncoding()); }

      } catch (UnsupportedEncodingException ex)

      { throw new WicketRuntimeException(ex.getMessage()); }

      }
      =======================

      Thanks.

      Attachments

        Activity

          People

            jcompagner Johan Compagner
            t_yano Tsutomu YANO
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: