Wicket
  1. Wicket
  2. WICKET-2795

Wicket removes first dollar from $$ markups with TextTemplate's interpolate() while $$ are commonly used in JavaScript libraries

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.6
    • Fix Version/s: None
    • Component/s: wicket
    • Labels:
    • Environment:
      Windows XP SP3, Apache Jetty 6.1.22

      Description

      Many JavaScript libraries such as jQuery and MooTools use $$ to find out arrays of elements. Having $$('blaa') is currently replaced by Wicket into $('blaa'). Wanted behavior is to replace all $$

      {...} with ${...}

      , not $$ with $.

      Possible fix (don't really have time to look at this atm):

      org.apache.wicket.util.template.VariableInterpolator:

      Row 111:

      while ((start = lowerPositive(string.indexOf("$$", pos), string.indexOf("${", pos))) != -1)
      {
      // Append text before possible variable
      buffer.append(string.substring(pos, start));

      if (string.charAt(start + 1) == '$')

      { buffer.append("$"); pos = start + 2; continue; }

      ...

      Shoud be changed to:

      while ((start = lowerPositive(string.indexOf("$${", pos), string.indexOf("${", pos))) != -1)
      {
      // Append text before possible variable
      buffer.append(string.substring(pos, start));

      if (string.charAt(start + 1) == '$' && string.charAt(start + 2) == '{')
      {
      buffer.append("$

      {"); pos = start + 3; continue; }

      ...

      (no JIRA markup for rich formatting available? uh)

        Activity

        Hide
        Igor Vaynberg added a comment -

        dont think there was a special reason, the code is quiet old.

        Show
        Igor Vaynberg added a comment - dont think there was a special reason, the code is quiet old.
        Hide
        Tuukka Mustonen added a comment -

        Oh that's quite true, I didn't think it through.

        Then, backslashes are commonly interpreted as ignore-the-next-character's-special-meaning and everyone knows about them already - was there some special reason for not selecting them for this as well so \$ for turning into $ and
        $ for turning into \$ and so on?

        Show
        Tuukka Mustonen added a comment - Oh that's quite true, I didn't think it through. Then, backslashes are commonly interpreted as ignore-the-next-character's-special-meaning and everyone knows about them already - was there some special reason for not selecting them for this as well so \$ for turning into $ and $ for turning into \$ and so on?
        Hide
        Igor Vaynberg added a comment -

        btw, the point behind the escape sequence is to simply allow $ to appear anywhere in the contents. for example a template can be

        $$$

        {amountInDollars}
        Show
        Igor Vaynberg added a comment - btw, the point behind the escape sequence is to simply allow $ to appear anywhere in the contents. for example a template can be $$$ {amountInDollars}
        Hide
        Igor Vaynberg added a comment -

        i understand that this is not convenient when working with javascript, unfortunately this has been in the codebase for a long time and cannot be changed without people rewriting their apps. maybe in 1.5 we can change it, but definitely not in 1.4

        Show
        Igor Vaynberg added a comment - i understand that this is not convenient when working with javascript, unfortunately this has been in the codebase for a long time and cannot be changed without people rewriting their apps. maybe in 1.5 we can change it, but definitely not in 1.4
        Hide
        Tuukka Mustonen added a comment - - edited

        I think the point behind the escape sequence is to allow leaving $

        {....}

        markups in templates, and that's all, no? Putting $$$$ would brake IDE support for JavaScript (not generically, but for specific libraries).

        As $variable expressions are not processed, this would be a safe thing to do.

        Now:

        $

        {...} gets interpolated
        $${...}

        gets turned into $

        {...}
        $$ will get processed (and will result in strange results with JS calls that have curly bracers like $$("el").each(functionI() {...}

        ); )

        After changes:

        $

        {...} gets processed
        $${...}

        gets turned into $

        {...}

        $$ will not get processed

        Quite propably I am missing something here?

        Show
        Tuukka Mustonen added a comment - - edited I think the point behind the escape sequence is to allow leaving $ {....} markups in templates, and that's all, no? Putting $$$$ would brake IDE support for JavaScript (not generically, but for specific libraries). As $variable expressions are not processed, this would be a safe thing to do. Now: $ {...} gets interpolated $${...} gets turned into $ {...} $$ will get processed (and will result in strange results with JS calls that have curly bracers like $$("el").each(functionI() {...} ); ) After changes: $ {...} gets processed $${...} gets turned into $ {...} $$ will not get processed Quite propably I am missing something here?
        Hide
        Igor Vaynberg added a comment -

        we wont fix this because it will change existing behavior, the $$ is our escape sequence, please use $$$$ in your code

        Show
        Igor Vaynberg added a comment - we wont fix this because it will change existing behavior, the $$ is our escape sequence, please use $$$$ in your code

          People

          • Assignee:
            Igor Vaynberg
            Reporter:
            Tuukka Mustonen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development