Permalink
Browse files

[#107] Tests demonstrating, and a fix to allow multi-line tags to be …

…broken by CRLF line breaks.
  • Loading branch information...
1 parent 6f4a1f2 commit df8c61b2f74548dc143117b704d12f473394156c @lukepfarrar lukepfarrar committed with mbknor Dec 15, 2011
View
2 framework/src/play/templates/GroovyTemplateCompiler.java
@@ -243,7 +243,7 @@ void action(boolean absolute) {
@Override
void startTag() {
tagIndex++;
- String tagText = parser.getToken().trim().replaceAll("\n", " ");
+ String tagText = parser.getToken().trim().replaceAll("\r", "").replaceAll("\n", " ");
String tagName = "";
String tagArgs = "";
boolean hasBody = !parser.checkNext().endsWith("/");
View
33 framework/test-src/play/templates/GroovyTemplateTest.java
@@ -7,6 +7,7 @@
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
public class GroovyTemplateTest {
@@ -92,5 +93,37 @@ private void internalVerifyCompilingExtremelyLongLinesWithSpecialCharAsLastCharB
args.put("name", "Morten");
assertThat( t.render( args ) ).isEqualTo(longString+": Morten");
}
+
+ // [#107] caused any tag broken with a CR to fail. (It would be compiled to list arg:items:....).
+ @Test
+ public void verifyCompilingWithCR() {
+ final String source = "#{list items:1..3,\ras:'i'}${i}#{/list}";
+ GroovyTemplate groovyTemplate = new GroovyTemplate("tag_broken_by_CR", source);
+ new GroovyTemplateCompiler().compile(groovyTemplate);
+ assertEquals("123",groovyTemplate.render());
+ }
+
+ @Test
+ public void verifyCompilingWithLF() {
+ final String source = "#{list items:1..3,\nas:'i'}${i}#{/list}";
+ GroovyTemplate groovyTemplate = new GroovyTemplate("tag_broken_by_LF", source);
+ new GroovyTemplateCompiler().compile(groovyTemplate);
+ assertEquals("123", groovyTemplate.render());
+ }
+ @Test
+ public void verifyCompilingWithCRLF() {
+ final String source = "#{list items:1..3,\r\nas:'i'}${i}#{/list}";
+ GroovyTemplate groovyTemplate = new GroovyTemplate("tag_broken_by_CRLF", source);
+ new GroovyTemplateCompiler().compile(groovyTemplate);
+ assertEquals("123", groovyTemplate.render());
+ }
+
+ @Test
+ public void verifyCompilingWithMultipleCRandLF() {
+ final String source = "#{list items:1..3,\r\n\r\r\n\nas:'i'}${i}#{/list}";
+ GroovyTemplate groovyTemplate = new GroovyTemplate("Broken_with_multiple_CR_and_LF", source);
+ new GroovyTemplateCompiler().compile(groovyTemplate);
+ assertEquals("123", groovyTemplate.render());
+ }
}

0 comments on commit df8c61b

Please sign in to comment.