groovy
  1. groovy
  2. GROOVY-399

Groovy Template quote escape problem

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Templating
    • Labels:
      None
    • Number of attachments :
      3

      Description

      The SimpleTemplateEngine got a problem with escaping quotes inside GStrings.

      "this" is tricky: ${hello + " " + hello}
      

      will be parsed to

      out.print("\"this\" is tricky: ${hello + \" \" + hello}");
      

      which is a problem for the current lexer as a GString must be a valid groovy statement.

      1. patch.txt
        1.0 kB
        Thomas Heller
      2. test.tar.gz
        11 kB
        Niall Gallagher
      3. test-closure.tar.gz
        13 kB
        Niall Gallagher

        Issue Links

          Activity

          Hide
          Niall Gallagher added a comment -

          The attached file is not exactly a patch but rather a rework of the parsing done for the templates. If it is reasonable at this stage to port the GStringTemplateEngine and SimpleTemplateEngine to this framework then I would be happy to do it.

          Attached you will find some test drivers and an example template with some "tricky" expressions. Don't know what licence to attach to these?

          Show
          Niall Gallagher added a comment - The attached file is not exactly a patch but rather a rework of the parsing done for the templates. If it is reasonable at this stage to port the GStringTemplateEngine and SimpleTemplateEngine to this framework then I would be happy to do it. Attached you will find some test drivers and an example template with some "tricky" expressions. Don't know what licence to attach to these?
          Hide
          Niall Gallagher added a comment -

          Whoops! in haste I did not attach a parser for the closure used by the GStringTemplateEngine. I have attached it on this upload. It produces an identical script to the one produced by the current GStringTemplateEngine, except it does not escape quotes within $

          {..}

          expressions. The following will generate the Groovy script from a template.

          java TestCascade template.groovy

          Show
          Niall Gallagher added a comment - Whoops! in haste I did not attach a parser for the closure used by the GStringTemplateEngine. I have attached it on this upload. It produces an identical script to the one produced by the current GStringTemplateEngine, except it does not escape quotes within $ {..} expressions. The following will generate the Groovy script from a template. java TestCascade template.groovy
          Hide
          Guillaume Laforge added a comment -

          Oh Template and Groovlet master!!!

          Show
          Guillaume Laforge added a comment - Oh Template and Groovlet master!!!
          Hide
          Christian Stein added a comment -

          Looking at http://jira.codehaus.org/browse/GROOVY-399 - we should write the test cases asap - before refactoring the whole parser stuff. After a first glimpse, it could help with all those char-by-char parser short-comings.

          Show
          Christian Stein added a comment - Looking at http://jira.codehaus.org/browse/GROOVY-399 - we should write the test cases asap - before refactoring the whole parser stuff. After a first glimpse, it could help with all those char-by-char parser short-comings.
          Hide
          Paul King added a comment -

          OK, I made a few changes to the existing code base so that the ugly problems with quotes inside (for now simple) GStrings goes away. Not as good as the other proposals listed here for a re-write but at least gets rid of the ugly cases for now.

          I also tried grafting in the current antlr GString parsing into the template codebase and made some progress but backed out as it was going to take a lot more time to finish than I have right now.

          Show
          Paul King added a comment - OK, I made a few changes to the existing code base so that the ugly problems with quotes inside (for now simple) GStrings goes away. Not as good as the other proposals listed here for a re-write but at least gets rid of the ugly cases for now. I also tried grafting in the current antlr GString parsing into the template codebase and made some progress but backed out as it was going to take a lot more time to finish than I have right now.

            People

            • Assignee:
              Unassigned
              Reporter:
              Thomas Heller
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: