groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Szymon Stępniak (JIRA) <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8701) StreamingTemplateEngine renders escaped character with backslash
Date Mon, 16 Jul 2018 10:33:00 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8701?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Szymon Stępniak updated GROOVY-8701:
------------------------------------
    Description: 
Using {{groovy.text.StreamingTemplateEngine}} to render a template containing escaped character
(e.g. {{\$}}) produces output containing escape character. Using the same template with {{groovy.text.GStringTemplateEngine}}
does not produce an output containing escape character.

The quickest way to reproduce the issue:

 
{code}
import groovy.text.StreamingTemplateEngine

def placeholders = [
  "StreamingTemplateEnginePlaceholder": "SOME_VALUE",
]
def templateContent = new File('test.php.template').text

def engine = new StreamingTemplateEngine()
def configContent = engine.createTemplate(templateContent)
  .make(placeholders)
  .toString()

println configContent
{code}

test.php.template

{code:php}
<?php
\$my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
?>
{code}

Output:

{code:php}
<?php
\$my_php_config_variable = "SOME_VALUE"
?>
{code}

When template does not escape dollar character then rendering such a template produces following
exception:

{code:bash}
Caught: groovy.text.TemplateExecutionException: Template execution error at line 2:
         1: <?php
     --> 2: $my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
         3: ?>

groovy.text.TemplateExecutionException: Template execution error at line 2:
         1: <?php
     --> 2: $my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
         3: ?>

	at test.run(test.groovy:9)
Caused by: groovy.lang.MissingPropertyException: No such property: my_php_config_variable
for class: groovy.tmp.templates.StreamingTemplateScript1
	... 1 more
{code}

  was:
Using {{groovy.text.StreamingTemplateEngine}} to render a template containing escaped character
(e.g. {{\$}}) produces output containing escape character. Using the same template with {{groovy.text.GStringTemplateEngine}}
does not produce an output containing escape character.

The quickest way to reproduce the issue:

 
{code}
import groovy.text.StreamingTemplateEngine

def placeholders = [
  "StreamingTemplateEnginePlaceholder": "SOME_VALUE",
]
def templateContent = new File('test.php.template').text

def engine = new StreamingTemplateEngine()
def configContent = engine.createTemplate(templateContent)
  .make(placeholders)
  .toString()

println configContent
{code}

test.php.template

{code:php}
<?php
\$my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
?>
{code}

Output:

{code:php}
<?php
\$my_php_config_variable = "SOME_VALUE"
?>
{code}


> StreamingTemplateEngine renders escaped character with backslash
> ----------------------------------------------------------------
>
>                 Key: GROOVY-8701
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8701
>             Project: Groovy
>          Issue Type: Bug
>          Components: Templating
>    Affects Versions: 2.5.1
>            Reporter: Szymon Stępniak
>            Priority: Minor
>
> Using {{groovy.text.StreamingTemplateEngine}} to render a template containing escaped
character (e.g. {{\$}}) produces output containing escape character. Using the same template with
{{groovy.text.GStringTemplateEngine}} does not produce an output containing escape character.
> The quickest way to reproduce the issue:
>  
> {code}
> import groovy.text.StreamingTemplateEngine
> def placeholders = [
>   "StreamingTemplateEnginePlaceholder": "SOME_VALUE",
> ]
> def templateContent = new File('test.php.template').text
> def engine = new StreamingTemplateEngine()
> def configContent = engine.createTemplate(templateContent)
>   .make(placeholders)
>   .toString()
> println configContent
> {code}
> test.php.template
> {code:php}
> <?php
> \$my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
> ?>
> {code}
> Output:
> {code:php}
> <?php
> \$my_php_config_variable = "SOME_VALUE"
> ?>
> {code}
> When template does not escape dollar character then rendering such a template produces
following exception:
> {code:bash}
> Caught: groovy.text.TemplateExecutionException: Template execution error at line 2:
>          1: <?php
>      --> 2: $my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
>          3: ?>
> groovy.text.TemplateExecutionException: Template execution error at line 2:
>          1: <?php
>      --> 2: $my_php_config_variable = "${StreamingTemplateEnginePlaceholder}"
>          3: ?>
> 	at test.run(test.groovy:9)
> Caused by: groovy.lang.MissingPropertyException: No such property: my_php_config_variable
for class: groovy.tmp.templates.StreamingTemplateScript1
> 	... 1 more
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message