Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 15fb59614 -> a546585e1


Refine `SimpleTemplateEngine` API to support escaping backslashes

(cherry picked from commit 099089e)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a546585e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a546585e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a546585e

Branch: refs/heads/GROOVY_2_6_X
Commit: a546585e1217cea2ff830826db42b8605a55ed5e
Parents: 15fb596
Author: danielsun1106 <realblue...@hotmail.com>
Authored: Sat Apr 7 02:09:03 2018 +0800
Committer: danielsun1106 <realblue...@hotmail.com>
Committed: Sat Apr 7 02:09:54 2018 +0800

----------------------------------------------------------------------
 src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy    |  3 ++-
 .../main/groovy/groovy/text/SimpleTemplateEngine.java   | 12 +++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a546585e/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy 
b/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
index 17f9120..0dc274c 100644
--- a/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
+++ b/src/test/groovy/bugs/groovy4585/Groovy4585Bug.groovy
@@ -20,7 +20,8 @@ package groovy.bugs.groovy4585
 
 class Groovy4585Bug extends GroovyTestCase {
     void test() {
-        def engineForBuildXml = new groovy.text.SimpleTemplateEngine(false, 
true)
+        def engineForBuildXml = new groovy.text.SimpleTemplateEngine(false)
+        engineForBuildXml.setEscapeBackslash(true)
         def templateForBuildXml = 
engineForBuildXml.createTemplate(this.getClass().getResource("/groovy/bugs/groovy4585/groovy4585.xml").text)
         String buildXmlContent = templateForBuildXml.make([names:['a', 'b', 
'c']]).toString()
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/a546585e/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
index 2c541f0..1893bd1 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
@@ -105,13 +105,8 @@ public class SimpleTemplateEngine extends TemplateEngine {
     }
 
     public SimpleTemplateEngine(boolean verbose) {
-        this(verbose, false);
-    }
-
-    public SimpleTemplateEngine(boolean verbose, boolean escapeBackslash) {
         this(GroovyShell.class.getClassLoader());
         setVerbose(verbose);
-        this.escapeBackslash = escapeBackslash;
     }
 
     public SimpleTemplateEngine(ClassLoader parentLoader) {
@@ -365,6 +360,13 @@ public class SimpleTemplateEngine extends TemplateEngine {
             }
             sw.write(";\nout.print(\"\"\"");
         }
+    }
 
+    public boolean isEscapeBackslash() {
+        return escapeBackslash;
+    }
+
+    public void setEscapeBackslash(boolean escapeBackslash) {
+        this.escapeBackslash = escapeBackslash;
     }
 }

Reply via email to