Wicket
  1. Wicket
  2. WICKET-3909

Encoding problem with JavaScriptRefrences

    Details

      Description

      Let we have a javascript which contains some strings (which eventually should be appended to DOM), and let we have a page in different encoding from UTF-8, like ISO-8859-2. The anomaly is the following:

      • If the encoding of the JS is UTF-8, then the Ajax query which injects the JS is working OK. The injected string looks like it should be, no magic chars. But if we don't use the JS from Ajax, but plain request, then the string is ugly because JS is in UTF-8, but the page is in ISO-8859-2.
      • If the encoding of the JS is the same as the Page then the response of the Ajax request will be ugly, but the plain non-ajax will be OK.
      1. WICKET-3909.patch
        8 kB
        Attila Király
      2. myproject.tar.gz
        18 kB
        Bálint Kriván

        Activity

        Hide
        Bálint Kriván added a comment -

        The attached quickstart project shows the problem.
        Steps to reproduce:

        • Click the Show button. You should see Árvíztűrő tükörfúrógép.
        • If you now refresh the browser you get doubled ugly chars.

        If you change the sample.js encoding to ISO-8859-2, then:

        • Click the Show button. You should see �rv�zt�r� t�k�rf�r�g�p.
        • If you now refresh you should see Árvíztűrő tükörfúrógép.
        Show
        Bálint Kriván added a comment - The attached quickstart project shows the problem. Steps to reproduce: Click the Show button. You should see Árvíztűrő tükörfúrógép. If you now refresh the browser you get doubled ugly chars. If you change the sample.js encoding to ISO-8859-2, then: Click the Show button. You should see �rv�zt�r� t�k�rf�r�g�p. If you now refresh you should see Árvíztűrő tükörfúrógép.
        Hide
        Attila Király added a comment -

        You have to specify the character encoding of the script file in the script tag with the charset attribute [1] if it differs from the page encoding. For example if I modify wicket to render all script tags with charset="UTF-8" attribute sour quickstart starts working.

        Imho wicket has no way to figure out the encoding of js files but maybe o.a.w.markup.html.IHeaderResponse.renderJavaScript* methods could be enhanced with an optionl charset attribute to handle cases like this.

        [1] W3School script@charset: http://www.w3schools.com/tags/att_script_charset.asp

        Show
        Attila Király added a comment - You have to specify the character encoding of the script file in the script tag with the charset attribute [1] if it differs from the page encoding. For example if I modify wicket to render all script tags with charset="UTF-8" attribute sour quickstart starts working. Imho wicket has no way to figure out the encoding of js files but maybe o.a.w.markup.html.IHeaderResponse.renderJavaScript* methods could be enhanced with an optionl charset attribute to handle cases like this. [1] W3School script@charset: http://www.w3schools.com/tags/att_script_charset.asp
        Hide
        Bálint Kriván added a comment -

        Thanks for pointing it out, could you throw some light on how to add charset to the tag?
        Currently I'm having this:
        response.renderJavaScriptReference(new JavaScriptResourceReference(TimeagoBehavior.class, "jquery.timeago.js"));
        I've digged myself into code and I didn't find any method or arg for this.

        Show
        Bálint Kriván added a comment - Thanks for pointing it out, could you throw some light on how to add charset to the tag? Currently I'm having this: response.renderJavaScriptReference(new JavaScriptResourceReference(TimeagoBehavior.class, "jquery.timeago.js")); I've digged myself into code and I didn't find any method or arg for this.
        Hide
        Attila Király added a comment -

        Attaching patch that adds new renderJavaScriptReference() method variants so the charset can be specified. 2 tests for the new feature also included.

        Show
        Attila Király added a comment - Attaching patch that adds new renderJavaScriptReference() method variants so the charset can be specified. 2 tests for the new feature also included.
        Hide
        Bálint Kriván added a comment -

        I can confirm it solves the bug. Thanks for providing the patch!

        Show
        Bálint Kriván added a comment - I can confirm it solves the bug. Thanks for providing the patch!
        Hide
        Martin Grigorov added a comment -

        The patch is applied.
        Thanks!

        Show
        Martin Grigorov added a comment - The patch is applied. Thanks!

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Bálint Kriván
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development