From 095c6f9a59d605d53234e10f43a1751a4672b6a3 Mon Sep 17 00:00:00 2001 From: Sean Scanlon Date: Sun, 27 Mar 2011 16:07:20 -0700 Subject: [PATCH] fix for using {{.}} in non-standards mode in non-standards mode (which is the default), {{.}} would be treated as a compound key, resulting in key not found exceptions. --- src/main/java/com/samskivert/mustache/Template.java | 3 ++- src/test/java/com/samskivert/mustache/MustacheTest.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/samskivert/mustache/Template.java b/src/main/java/com/samskivert/mustache/Template.java index 33229f9..5999f7d 100644 --- a/src/main/java/com/samskivert/mustache/Template.java +++ b/src/main/java/com/samskivert/mustache/Template.java @@ -80,7 +80,8 @@ public class Template if (!_compiler.standardsMode) { // if we're dealing with a compound key, resolve each component and use the result to // resolve the subsequent component and so forth - if (name.indexOf(".") != -1) { + + if (name.indexOf(DOT_NAME) > 0) { String[] comps = name.split("\\."); // we want to allow the first component of a compound key to be located in a parent // context, but once we're selecting sub-components, they must only be resolved in the diff --git a/src/test/java/com/samskivert/mustache/MustacheTest.java b/src/test/java/com/samskivert/mustache/MustacheTest.java index 2c11850..78acb01 100644 --- a/src/test/java/com/samskivert/mustache/MustacheTest.java +++ b/src/test/java/com/samskivert/mustache/MustacheTest.java @@ -169,11 +169,14 @@ public class MustacheTest @Test public void testTopLevelThis () { assertEquals("bar", Mustache.compiler().compile("{{this}}").execute("bar")); + assertEquals("bar", Mustache.compiler().compile("{{.}}").execute("bar")); } @Test public void testNestedThis () { assertEquals("barbazbif", Mustache.compiler().compile("{{#things}}{{this}}{{/things}}"). execute(context("things", Arrays.asList("bar", "baz", "bif")))); + assertEquals("barbazbif", Mustache.compiler().compile("{{#things}}{{.}}{{/things}}"). + execute(context("things", Arrays.asList("bar", "baz", "bif")))); } @Test public void testStructuredVariable () {