Velocity
  1. Velocity
  2. VELOCITY-555

Escape quotes in interpolated strings (both ' and ") by doubling them ('' and "")

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.7, 2.x
    • Component/s: None
    • Labels:
      None

      Description

      More than a few years, the issue of escaping quotes in interpolated strings was discussed at some length. Eventually, the list came to a consensus that we should escape them by doubling them, since this would be (or at least very nearly be) backwards compatible and provide a simple solution for this much-wanted feature.

      Geir had working code for this and even posted a test jar, IIRC. So, many of us thought that this had made it into the 1.5 codebase. But the code never got checked in and may have been lost. Assuming Geir can't find the old code or the time to duplicate the effort, we should still try to implement this.

      This issue is open to remind us of that. If i get around to digging up links to the relevant threads, i will post those in the comments of this issue.

      1. velocity-555.patch
        5 kB
        Jarkko Viinamäki

        Issue Links

          Activity

          Hide
          Nathan Bubna added a comment -

          Lacking a champion for this, i don't think we can plan on this for 1.6.

          Show
          Nathan Bubna added a comment - Lacking a champion for this, i don't think we can plan on this for 1.6.
          Hide
          Jarkko Viinamäki added a comment -

          This special patch implements a few things:

          1. Backslashes are treated as regular characters in string literals (except when user defines Unicode characters). Thus e.g. #set($foo = "\") works.

          2. Double and single quotes can be escaped by repeating them. #set($foo = "yeah ""YEAH"" yeah!") $foo would print yeah "YEAH" yeah!

          Thus this patch should more or less fix issues related to VELOCITY-587 and VELOCITY-709 as well.

          All tests pass but these changes may break some existing user templates. Careful review is needed before commiting this.

          Show
          Jarkko Viinamäki added a comment - This special patch implements a few things: 1. Backslashes are treated as regular characters in string literals (except when user defines Unicode characters). Thus e.g. #set($foo = "\") works. 2. Double and single quotes can be escaped by repeating them. #set($foo = "yeah ""YEAH"" yeah!") $foo would print yeah "YEAH" yeah! Thus this patch should more or less fix issues related to VELOCITY-587 and VELOCITY-709 as well. All tests pass but these changes may break some existing user templates. Careful review is needed before commiting this.
          Hide
          Nathan Bubna added a comment -

          Thanks, Jarkko!

          Show
          Nathan Bubna added a comment - Thanks, Jarkko!
          Hide
          Fionn Ziegler added a comment - - edited

          Hi together,
          I'm not sure whether this is the correct way to ask or if that is related but it would be really helpful if you could point me to the correct direction. After upgrading the velocity version to 1.7 I get:

          Lexical error, Encountered: "u" (117), after : "" at velocity/mediaImpexTemplate.vm[line 58, column 50]
          for:
          engine.getTemplate("mediaImpexTemplate.vm", "UTF-8");

          the respective line is:
          ...
          57: ## specifically remove any media code weve been given to ensure the change will sync
          58: REMOVE PGMedia;code[unique=true];$catalogVersion[unique=true]

          Any idea what I'm doing wrong here?

          Thanks,
          Fionn

          Show
          Fionn Ziegler added a comment - - edited Hi together, I'm not sure whether this is the correct way to ask or if that is related but it would be really helpful if you could point me to the correct direction. After upgrading the velocity version to 1.7 I get: Lexical error, Encountered: "u" (117), after : "" at velocity/mediaImpexTemplate.vm [line 58, column 50] for: engine.getTemplate("mediaImpexTemplate.vm", "UTF-8"); the respective line is: ... 57: ## specifically remove any media code weve been given to ensure the change will sync 58: REMOVE PGMedia;code [unique=true] ;$catalogVersion [unique=true] Any idea what I'm doing wrong here? Thanks, Fionn
          Hide
          Nathan Bubna added a comment -

          This is a question for the user@velocity.apache.org list. It is not related to this issue. (Hint: use formal syntax)

          Show
          Nathan Bubna added a comment - This is a question for the user@velocity.apache.org list. It is not related to this issue. (Hint: use formal syntax)

            People

            • Assignee:
              Unassigned
              Reporter:
              Nathan Bubna
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development