[ 
https://issues.apache.org/jira/browse/GROOVY-4585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16428345#comment-16428345
 ] 

ASF GitHub Bot commented on GROOVY-4585:
----------------------------------------

GitHub user danielsun1106 opened a pull request:

    https://github.com/apache/groovy/pull/681

    GROOVY-4585: backslash can not be escaped by `SimpleTemplateEngine`

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/danielsun1106/groovy GROOVY-4585

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/681.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #681
    
----
commit 4b44cb1a78e7cfc512f69f2cdc4ba9d0359d99d9
Author: Daniel Sun <realbluesun@...>
Date:   2018-04-06T13:44:49Z

    GROOVY-4585: backslash can not be escaped by `SimpleTemplateEngine`

----


> backslash can not be escaped by `SimpleTemplateEngine`
> ------------------------------------------------------
>
>                 Key: GROOVY-4585
>                 URL: https://issues.apache.org/jira/browse/GROOVY-4585
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Templating
>    Affects Versions: 1.8-beta-2
>         Environment: jdk1.6u16, windows xp
>            Reporter: Daniel Sun
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 1.8-beta-4
>
>         Attachments: SimpleTemplateEngine.java.patch, 
> SimpleTemplateEngine.java.v2.patch, TEST_for_GROOVY-4585.groovy, 
> testcase.v2.zip
>
>
> 1, bug:fail to escape back slash
>   If a back slash(\) in the template, SimpleTemplateEngine can not escape it, 
> as a result, an exception throwed.
> 2, new feature: add support to escape dollar char
>   Now we can escape dollar char with dollar char, for example: $$
> Enjoy the patch ;)
> {code}
> import groovy.text.*
> String templateContent = new 
> File(/D:\_APPS\groovy_apps\TemplateEnginTest\echo.xml/).text
> def engineForBuildXml = new SimpleTemplateEngine()
> def templateForBuildXml = engineForBuildXml.createTemplate(templateContent)
> String buildXmlContent = templateForBuildXml.make([names:['a', 'b', 
> 'c']]).toString()
> println buildXmlContent
> {code}
> {code}
> <?xml version="1.0" encoding="GB2312"?>
> <project name="projBuild" default="projBuild" basedir=".">
>       <property name="drive" value="d:\" />
>     <target name="projBuild">
>               <%for (int i = 0; i < names.size(); i++) {%>
>                       <exec dir="$${drive}" executable="echo">
>                                 <arg line="${names[i]}"/>
>                       </exec>
>               <%}%>
>     </target>
> </project>
> {code}



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

Reply via email to