Velocity
  1. Velocity
  2. VELOCITY-126

String containing '##' is treated as unterminated String.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.5
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: All

      Description

      The following template snippet

      $

      {System_err.println("###############################################")}

      Results in this output:
      [INFO,STDERR] [rrd] 1042589262000 Error in interpolating string literal :
      org.apache.velocity.runtime.parser.ParseException: Lexical error:
      org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1,
      column 49. Encountered: <EOF> after : ""

      If you're wondering what I'm doing, I've got System.err passed into velocity as
      System_err

        Activity

        Hide
        Daniel Rall added a comment -

        This is working as expected. Everything after the ## comment characters is
        ignored. You can either single-quote your string to prevent interpolation, or
        backslash escape the characters which you don't want interpolated.

        Marking as a possible enhancement for the future. This would involve some
        parser changes.

        Show
        Daniel Rall added a comment - This is working as expected. Everything after the ## comment characters is ignored. You can either single-quote your string to prevent interpolation, or backslash escape the characters which you don't want interpolated. Marking as a possible enhancement for the future. This would involve some parser changes.
        Hide
        Claude Brisson added a comment -

        It is not a consistent behaviour.

        Whether you interpolate ## and #* and *# INSIDE the double-quoted string (hence,
        "##foo"==""), whether you don't interpolate comments inside strings at all. And
        I strongly recomend the latter : that's the standard behaviour in all other
        languages I know of.

        Right now, with 1.5-dev, I've got:

        [2004/11/16 03:05:10.405] Velocity [error] Error in interpolating string
        literal : java.lang.StringIndexOutOfBoundsException: String index out of range: -1

        with no information about the location and no stacktrace... (it seems like a new
        bug appeared in the handling of the so-called lexical error)

        I put it back as a bug rather than as an enhancement, at least because Velocity
        should display something like "unterminated string at line...".

        Show
        Claude Brisson added a comment - It is not a consistent behaviour. Whether you interpolate ## and #* and *# INSIDE the double-quoted string (hence, "##foo"==""), whether you don't interpolate comments inside strings at all. And I strongly recomend the latter : that's the standard behaviour in all other languages I know of. Right now, with 1.5-dev, I've got: [2004/11/16 03:05:10.405] Velocity [error] Error in interpolating string literal : java.lang.StringIndexOutOfBoundsException: String index out of range: -1 with no information about the location and no stacktrace... (it seems like a new bug appeared in the handling of the so-called lexical error) I put it back as a bug rather than as an enhancement, at least because Velocity should display something like "unterminated string at line...".
        Hide
        Will Glass-Husain added a comment -

        After thinking about this, I believe we should keep the intent of current behavior. Comments are interpreted in double quote strings and ignored in single quote strings. I agree with Claude this is a little odd, but there's a certain logic there none the less. Regardless, we can't change it as existing users may depend on this behavior.

        There was an additional problem that caused the exception. The final character before the ## was being chopped off. I've fixed this bug which should remove the exception. I also added more test cases into "interpolation.vm" to test different situations.

        "test##test" => "test"
        'test##test' => 'test##test'
        "######" => ""

        My advice is to use single quotes when you want ## symbols to appear in a String.

        Show
        Will Glass-Husain added a comment - After thinking about this, I believe we should keep the intent of current behavior. Comments are interpreted in double quote strings and ignored in single quote strings. I agree with Claude this is a little odd, but there's a certain logic there none the less. Regardless, we can't change it as existing users may depend on this behavior. There was an additional problem that caused the exception. The final character before the ## was being chopped off. I've fixed this bug which should remove the exception. I also added more test cases into "interpolation.vm" to test different situations. "test##test" => "test" 'test##test' => 'test##test' "######" => "" My advice is to use single quotes when you want ## symbols to appear in a String.
        Hide
        Henning Schmiedehausen added a comment -

        Close all resolved issues for Engine 1.5 release.

        Show
        Henning Schmiedehausen added a comment - Close all resolved issues for Engine 1.5 release.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jimmy Wan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development