Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4585

backslash can not be escaped by `SimpleTemplateEngine`

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0-alpha-1, 2.6.0-alpha-3, 2.5.0-rc-1, 2.4.15
    • Templating
    • None
    • jdk1.6u16, windows xp
    • Patch

    Description

      If a backslash exists in the template, SimpleTemplateEngine can not escape it, as a result, an exception throwed.

      Enjoy the patch

      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
      
      <?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>
      
      

      Attachments

        1. testcase.v2.zip
          0.7 kB
          Daniel Sun
        2. TEST_for_GROOVY-4585.groovy
          1 kB
          Daniel Sun
        3. SimpleTemplateEngine.java.v2.patch
          0.5 kB
          Daniel Sun
        4. SimpleTemplateEngine.java.patch
          3 kB
          Daniel Sun

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              daniel_sun Daniel Sun
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: