From 304f71a02f7a6be5dec373e0cd00eab3de11d8f3 Mon Sep 17 00:00:00 2001 From: Sam Pullara Date: Fri, 25 Aug 2023 14:35:46 -0700 Subject: [PATCH] ISSUE-291: fix substring issue with empty dot --- .../mustachejava/reflect/AbstractObjectHandler.java | 3 ++- .../github/mustachejava/reflect/BaseObjectHandler.java | 1 + .../java/com/github/mustachejava/InterpreterTest.java | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/src/main/java/com/github/mustachejava/reflect/AbstractObjectHandler.java b/compiler/src/main/java/com/github/mustachejava/reflect/AbstractObjectHandler.java index 9ec48e1c..6aba6fe6 100644 --- a/compiler/src/main/java/com/github/mustachejava/reflect/AbstractObjectHandler.java +++ b/compiler/src/main/java/com/github/mustachejava/reflect/AbstractObjectHandler.java @@ -10,7 +10,7 @@ import java.util.Optional; -abstract class AbstractObjectHandler implements ObjectHandler { +public abstract class AbstractObjectHandler implements ObjectHandler { protected static final Object NOT_FOUND = new Object(); @@ -27,6 +27,7 @@ public Object coerce(Object object) { return object; } + @Override public Writer falsey(Iteration iteration, Writer writer, Object object, List scopes) { if (object != null) { diff --git a/compiler/src/main/java/com/github/mustachejava/reflect/BaseObjectHandler.java b/compiler/src/main/java/com/github/mustachejava/reflect/BaseObjectHandler.java index e908e1db..5d326145 100644 --- a/compiler/src/main/java/com/github/mustachejava/reflect/BaseObjectHandler.java +++ b/compiler/src/main/java/com/github/mustachejava/reflect/BaseObjectHandler.java @@ -66,6 +66,7 @@ protected AccessibleObject findMember(Class sClass, String name) { } private AccessibleObject findMemberOnClass(Class sClass, String name) { + if (name.isEmpty()) return null; AccessibleObject ao; try { ao = getMethod(sClass, name); diff --git a/compiler/src/test/java/com/github/mustachejava/InterpreterTest.java b/compiler/src/test/java/com/github/mustachejava/InterpreterTest.java index 47d3171f..f3a6af1f 100644 --- a/compiler/src/test/java/com/github/mustachejava/InterpreterTest.java +++ b/compiler/src/test/java/com/github/mustachejava/InterpreterTest.java @@ -1298,6 +1298,16 @@ public void testInvalidDelimiters() { } } + public void testEmptyDot() { + MustacheFactory mf = createMustacheFactory(); + StringWriter sw = new StringWriter(); + Mustache mustache = mf.compile(new StringReader("{{No.}}"), "template"); + Map scope = new HashMap<>(); + scope.put("No", "1"); + mustache.execute(sw, scope); + System.out.println(sw); + } + public void testTemplateFunction() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#i}}{{{test}}}{{f}}{{/i}}" +