Velocity
  1. Velocity
  2. VELOCITY-43

can't parse text immediately after #else

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

      Description

      I need to have a macro that returns a string with no newlines or
      leading/trailing spaces. The problem I found was that something like:

      #macro( test2 $n)
      #if($n<5)small#elselarge#end
      #end

      does not recognize the #else token. It produces the string "small#elselarge"
      or ""

      1. ASF.LICENSE.NOT.GRANTED--curly-directive.cmp
        0.1 kB
        Will Glass-Husain
      2. ASF.LICENSE.NOT.GRANTED--curly-directive.vm
        0.4 kB
        Will Glass-Husain
      3. ASF.LICENSE.NOT.GRANTED--Parser.jjt.patch
        3 kB
        Will Glass-Husain
      4. ASF.LICENSE.NOT.GRANTED--Parser.jjt.patch2
        3 kB
        Will Glass-Husain

        Activity

        Jim Rudnicki created issue -
        Hide
        Geir Magnusson Jr added a comment -

        thanks. acknowledged.

        Show
        Geir Magnusson Jr added a comment - thanks. acknowledged.
        Hide
        Will Glass-Husain added a comment -

        Found this old issue in Bugzilla.

        I've hit this problem too with my users, in which they want to put text right
        after an else but can't.

        #if($n<5)small#elselarge#end

        I've come up with a patch to fix this bug? (feature?) After applying the
        patch, ant test works, as does the example above.

        One small compatibility issue: you can no longer create a custom directive
        that starts with #else. (e.g. #elseorwhat). I consider this a fairly small
        issues as perhaps 1% of Velocity developers make custom directives, and I
        suspect less than 1% of those would start a directive with #else. (Note that
        the built in directive #elseif still works).

        Show
        Will Glass-Husain added a comment - Found this old issue in Bugzilla. I've hit this problem too with my users, in which they want to put text right after an else but can't. #if($n<5)small#elselarge#end I've come up with a patch to fix this bug? (feature?) After applying the patch, ant test works, as does the example above. One small compatibility issue: you can no longer create a custom directive that starts with #else. (e.g. #elseorwhat). I consider this a fairly small issues as perhaps 1% of Velocity developers make custom directives, and I suspect less than 1% of those would start a directive with #else. (Note that the built in directive #elseif still works).
        Hide
        Will Glass-Husain added a comment -

        Created an attachment (id=8932)
        patch to Parser.jjt and testcases. (Needs javacc to be run before compiling)

        Show
        Will Glass-Husain added a comment - Created an attachment (id=8932) patch to Parser.jjt and testcases. (Needs javacc to be run before compiling)
        Hide
        Nathan Bubna added a comment -

        for interested parties:

        the canonical workaround for this bug is using an empty block comment:

        #if( $foo )bar#else#*#baz#end#*#woogie

        also, there have been past discussions about adding a formal directive syntax.
        IIRC, a common suggestion was to mirror the formal reference syntax:

        #

        {if( $foo )}

        bar#

        {else}

        baz#

        {end}

        woogie

        IMHO, something like that would be less of a hack than disallowing custom
        directives that start with 'else' or 'end' (or 'stop' if #stop ever becomes
        legitimate).

        Show
        Nathan Bubna added a comment - for interested parties: the canonical workaround for this bug is using an empty block comment: #if( $foo )bar#else#* #baz#end# *#woogie also, there have been past discussions about adding a formal directive syntax. IIRC, a common suggestion was to mirror the formal reference syntax: # {if( $foo )} bar# {else} baz# {end} woogie IMHO, something like that would be less of a hack than disallowing custom directives that start with 'else' or 'end' (or 'stop' if #stop ever becomes legitimate).
        Hide
        Will Glass-Husain added a comment -

        Following Nathan's suggestion, here's an alternate patch to allow braces
        around directives. It's mostly useful for #else, #stop and #end (directives
        without anything following), but for consistency works for all directives.
        (Including macros and user defined directives). This means you can now do the
        following:

        #if( $foo )bar#

        {else}

        baz#

        {end}

        woogie

        which is probably clearer than the current workaround.

        Note that I've included "Parser.jjt" and some test cases. You'll need to run
        javacc and add the test cases to "template.properties" so they are run by test-
        template.

        Show
        Will Glass-Husain added a comment - Following Nathan's suggestion, here's an alternate patch to allow braces around directives. It's mostly useful for #else, #stop and #end (directives without anything following), but for consistency works for all directives. (Including macros and user defined directives). This means you can now do the following: #if( $foo )bar# {else} baz# {end} woogie which is probably clearer than the current workaround. Note that I've included "Parser.jjt" and some test cases. You'll need to run javacc and add the test cases to "template.properties" so they are run by test- template.
        Hide
        Will Glass-Husain added a comment -

        Created an attachment (id=8991)
        patch to Parser.jjt to add curly braces around directives

        Show
        Will Glass-Husain added a comment - Created an attachment (id=8991) patch to Parser.jjt to add curly braces around directives
        Hide
        Will Glass-Husain added a comment -

        Created an attachment (id=8992)
        curly-directive.vm (test case)

        Show
        Will Glass-Husain added a comment - Created an attachment (id=8992) curly-directive.vm (test case)
        Hide
        Will Glass-Husain added a comment -

        Created an attachment (id=8993)
        curly-directive.cmp (test case)

        Show
        Will Glass-Husain added a comment - Created an attachment (id=8993) curly-directive.cmp (test case)
        Hide
        Will Glass-Husain added a comment -

        Patch entered, with documentation changes. (Need updates to
        Spanish/Finnish/French versions, but that's another bug). Revision # 125338

        Show
        Will Glass-Husain added a comment - Patch entered, with documentation changes. (Need updates to Spanish/Finnish/French versions, but that's another bug). Revision # 125338
        Jeff Turner made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 7189 12314913
        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.
        Henning Schmiedehausen made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Workflow jira [ 12324918 ] Default workflow, editable Closed status [ 12551405 ]
        Mark Thomas made changes -
        Assignee Velocity-Dev List [ velocity-dev@jakarta.apache.org ]
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551405 ] jira [ 12552107 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Jim Rudnicki
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development