You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Paul Huijnen (JIRA)" <ji...@apache.org> on 2014/02/10 20:43:20 UTC

[jira] [Created] (WICKET-5504) AjaxRequestTarget.append/prependJavaScript cannot handle scripts with new-lines anymore

Paul Huijnen created WICKET-5504:
------------------------------------

             Summary: AjaxRequestTarget.append/prependJavaScript cannot handle scripts with new-lines anymore
                 Key: WICKET-5504
                 URL: https://issues.apache.org/jira/browse/WICKET-5504
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 6.13.0, 6.12.0
            Reporter: Paul Huijnen


Previously (version <= 6.0.8, but I suspect <= 6.0.11) , code like the following worked:
{code}
public void onSomething(AjaxRequestTarget target) {
target.prependJavaScript(
   "notify|jQuery('#someSelector').slideUp({\n" +
      "   complete: function() {\n" +
      "        doSomething();\n" +
      "        notify();\n" +
      "   }\n" +
      "});"
);
}
{code}

Note two things about this code:
* it uses the "notify|...." method to delay execution of other scripts until the animation is complete;
* it contains some new line characters.

In Wicket 6.0.12 (and 6.0.13) this script fails silently: the slideUp doesn't get executed.

When I remove the new-line-characters "\n" from the script, it works again.

Cause: line 1075 of wicket-ajax-jquery.js states:
{code}
var scriptSplitterR = new RegExp("\\(function\\(\\)\\{.*?}\\)\\(\\);", 'gi');
{code}
This regular expression does NOT match my script, while it should. This is caused by the the dot not matching the new line character.

A solution (according to various sources) could be the following, as [\S\s] matches any character (including new line characters):
{code}
var scriptSplitterR = new RegExp("\\(function\\(\\)\\{[\s\S]*?}\\)\\(\\);", 'gi');
{code}

Additional info: on github, I see the following lines in wicket-ajax-jquery.js have changed between 6.0.11 and 6.0.12:
{code}
var scripts = cleanArray(text.split(scriptSplitterR));
{code}
has become:
{code}
var scripts = [];
var scr;
while ( (scr = scriptSplitterR.exec(text) ) != null ) {
    scripts.push(scr[0]);
}
{code}
I suspect this change now causes my little problem.
   



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)