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

AjaxRequestTarget.append/prependJavaScript cannot handle scripts with new-lines anymore

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.12.0, 6.13.0
    • Fix Version/s: 7.0.0-M1, 6.15.0
    • Component/s: wicket
    • Labels:
      None

      Description

      Previously (version <= 6.0.8, but I suspect <= 6.0.11) , code like the following worked:

      public void onSomething(AjaxRequestTarget target) {
      target.prependJavaScript(
      "notify|jQuery('#someSelector').slideUp({\n" +
      " complete: function()

      {\n" + " doSomething();\n" + " notify();\n" + " }

      \n" +
      "});"
      );
      }

      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:

      var scriptSplitterR = new RegExp("\\(function\\(\\)

      {.*?}

      \\)\\(
      );", 'gi');

      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):

      var scriptSplitterR = new RegExp("\\(function\\(\\)

      {[\s\S]*?}

      \\)\\(
      );", 'gi');

      Additional info: on github, I see the following lines in wicket-ajax-jquery.js have changed between 6.0.11 and 6.0.12:

      var scripts = cleanArray(text.split(scriptSplitterR));

      has become:

      var scripts = [];
      var scr;
      while ( (scr = scriptSplitterR.exec(text) ) != null ) {
      scripts.push(scr[0]);
      }

      I suspect this change now causes my little problem.

        Attachments

          Activity

            People

            • Assignee:
              mgrigorov Martin Grigorov
              Reporter:
              p.huijnen Paul Huijnen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: