Author: julien_viet
Date: 2010-10-14 17:44:04 -0400 (Thu, 14 Oct 2010)
New Revision: 4672
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java
portal/trunk/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
Log:
GTNPORTAL-1563: Backslash not properly handled in gtmpl
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java 2010-10-14
19:54:25 UTC (rev 4671)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java 2010-10-14
21:44:04 UTC (rev 4672)
@@ -55,7 +55,9 @@
GSTRING_CURLY_EXPR,
- GSTRING_EXPR
+ GSTRING_EXPR,
+
+ BACKSLASH
}
public List<TemplateSection> parse(String s)
@@ -127,6 +129,10 @@
{
status = Status.START_ANGLE;
}
+ else if (c == '\\')
+ {
+ status = Status.BACKSLASH;
+ }
else if (c == '$')
{
status = Status.MAYBE_GSTRING_EXPR;
@@ -286,6 +292,11 @@
accumulator.append(c);
}
break;
+ case BACKSLASH:
+ accumulator.append('\\');
+ accumulator.append(c);
+ status = Status.TEXT;
+ break;
default:
throw new AssertionError();
}
Modified:
portal/trunk/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
---
portal/trunk/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2010-10-14
19:54:25 UTC (rev 4671)
+++
portal/trunk/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2010-10-14
21:44:04 UTC (rev 4672)
@@ -173,7 +173,7 @@
assertEquals("bar", s);
}
- public void testGString2() throws Exception
+ public void testQuoteAfterGString() throws Exception
{
GroovyTemplate template = new GroovyTemplate("$foo\"");
Map<String, String> context = new HashMap<String, String>();
@@ -182,6 +182,51 @@
assertEquals("bar\"", s);
}
+ public void testDollarInExpression() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%= \"$foo\"
%>");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("bar", s);
+ }
+
+ public void testEscapeDollarInExpression() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%= \"\\$foo\"
%>");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("$foo", s);
+ }
+
+ public void testEscapeDollarInText() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("\\$foo");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("$foo", s);
+ }
+
+ public void testDollarInScriplet() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%
out.print(\"$foo\") %>");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("bar", s);
+ }
+
+ public void testEscapeDollarInScriplet() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%
out.print(\"\\$foo\") %>");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("$foo", s);
+ }
+
public void testQuote() throws Exception
{
GroovyTemplate template = new GroovyTemplate("\"");