Added support for the triple mustache! {{{foo}}} which means "don't escape HTML

in the replacement for this tag." This is already supported via {{&foo}} as
well, but we like to be thorough.

Also generate MustacheParseException when parsing (a subclass of
MustacheException) mostly for convenience in testing.
This commit is contained in:
Michael Bayne
2011-02-28 20:15:45 -08:00
parent 04ea4b0cc0
commit cd4db4293e
4 changed files with 79 additions and 15 deletions
@@ -112,6 +112,28 @@ public class MustacheTest
test("foobar", "foo{{! nothing to see here}}bar", new Object());
}
@Test public void testUnescapeHTML () {
assertEquals("<b>", Mustache.compiler().escapeHTML(true).compile("{{&a}}").
execute(context("a", "<b>")));
assertEquals("<b>", Mustache.compiler().escapeHTML(true).compile("{{{a}}}").
execute(context("a", "<b>")));
// make sure these also work when escape HTML is off
assertEquals("<b>", Mustache.compiler().escapeHTML(false).compile("{{&a}}").
execute(context("a", "<b>")));
assertEquals("<b>", Mustache.compiler().escapeHTML(false).compile("{{{a}}}").
execute(context("a", "<b>")));
}
@Test(expected = MustacheParseException.class)
public void testDanglingTag () {
Mustache.compiler().escapeHTML(true).compile("{{a").execute(context("a", "<b>"));
}
@Test(expected = MustacheParseException.class)
public void testInvalidUnescapeHTML () {
Mustache.compiler().escapeHTML(true).compile("{{{a}}").execute(context("a", "<b>"));
}
@Test public void testEscapeHTML () {
assertEquals("&lt;b&gt;", Mustache.compiler().compile("{{a}}").
execute(context("a", "<b>")));