[gatein-commits] gatein SVN: r5054 - in exo/portal/branches/3.1.x/component/scripting/src: test/java/org/exoplatform/groovyscript and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Nov 12 02:31:50 EST 2010
Author: trong.tran
Date: 2010-11-12 02:31:50 -0500 (Fri, 12 Nov 2010)
New Revision: 5054
Modified:
exo/portal/branches/3.1.x/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java
exo/portal/branches/3.1.x/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
Log:
GTNPORTAL-1563 Backslash not properly handled in gtmpl
Modified: exo/portal/branches/3.1.x/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java
===================================================================
--- exo/portal/branches/3.1.x/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java 2010-11-12 06:59:11 UTC (rev 5053)
+++ exo/portal/branches/3.1.x/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java 2010-11-12 07:31:50 UTC (rev 5054)
@@ -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: exo/portal/branches/3.1.x/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
--- exo/portal/branches/3.1.x/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2010-11-12 06:59:11 UTC (rev 5053)
+++ exo/portal/branches/3.1.x/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2010-11-12 07:31:50 UTC (rev 5054)
@@ -128,7 +128,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>();
@@ -137,6 +137,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("\"");
More information about the gatein-commits
mailing list