May as well report the bogus final char if we can.

This commit is contained in:
Michael Bayne
2014-03-12 11:31:16 -07:00
parent d1c8a665a9
commit 8998b5f11e
2 changed files with 16 additions and 9 deletions
@@ -451,17 +451,18 @@ public class Mustache
// if the delimiters are {{ and }}, and the tag starts with {{{ then // if the delimiters are {{ and }}, and the tag starts with {{{ then
// require that it end with }}} and disable escaping // require that it end with }}} and disable escaping
if (delims.isStaches() && text.charAt(0) == delims.start1) { if (delims.isStaches() && text.charAt(0) == delims.start1) {
try { // we've only parsed }} at this point, so we have to slurp in another
// we've only parsed }} at this point, so we have to slurp in // character from the input stream and check it
// another character from the input stream and check it int end3;
int end3 = (char)source.read(); try { end3 = source.read(); }
if (end3 != '}') { catch (IOException e) {
throw new MustacheParseException(
"Invalid triple-mustache tag: {{" + text + "}}", line);
}
} catch (IOException e) {
throw new MustacheException(e); throw new MustacheException(e);
} }
if (end3 != '}') {
String got = (end3 == -1) ? "" : String.valueOf((char)end3);
throw new MustacheParseException(
"Invalid triple-mustache tag: {{" + text + "}}" + got, line);
}
// convert it into (equivalent) {{&text}} which addTagSegment handles // convert it into (equivalent) {{&text}} which addTagSegment handles
text.replace(0, 1, "&"); text.replace(0, 1, "&");
} }
@@ -590,6 +590,12 @@ public class MustacheTest
} catch (MustacheParseException e) { } catch (MustacheParseException e) {
assertEquals("Invalid triple-mustache tag: {{{foo}} @ line 1", e.getMessage()); assertEquals("Invalid triple-mustache tag: {{{foo}} @ line 1", e.getMessage());
} }
try {
Mustache.compiler().compile("{{{foo}}]");
fail("Expected MustacheParseException");
} catch (MustacheParseException e) {
assertEquals("Invalid triple-mustache tag: {{{foo}}] @ line 1", e.getMessage());
}
} }
@Test public void testNullValueGetsNullDefault () { @Test public void testNullValueGetsNullDefault () {