diff --git a/src/main/java/com/hubspot/jinjava/el/JinjavaInterpreterResolver.java b/src/main/java/com/hubspot/jinjava/el/JinjavaInterpreterResolver.java index 7f57b9689..009348dc3 100644 --- a/src/main/java/com/hubspot/jinjava/el/JinjavaInterpreterResolver.java +++ b/src/main/java/com/hubspot/jinjava/el/JinjavaInterpreterResolver.java @@ -91,10 +91,11 @@ public Object invoke( try { Object methodProperty = getValue(context, base, method, false); if (methodProperty instanceof AbstractCallableMethod) { - context.setPropertyResolved(true); - return interpreter.getContext().isValidationMode() + Object result = interpreter.getContext().isValidationMode() ? "" : ((AbstractCallableMethod) methodProperty).evaluate(params); + context.setPropertyResolved(true); + return result; } } catch (IllegalArgumentException e) { // failed to access property, continue with method calls diff --git a/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java b/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java index 6845810c7..a6d3fa7c5 100644 --- a/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java +++ b/src/test/java/com/hubspot/jinjava/interpret/JinjavaInterpreterTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.hubspot.jinjava.Jinjava; import com.hubspot.jinjava.JinjavaConfig; @@ -278,6 +279,20 @@ public void itCanPreserveRawTags() { assertThat(renderResult.hasErrors()).isFalse(); } + @Test + public void itKnowsThatMethodIsResolved() { + // Tests fix of bug where an error when an AstMethod is called would cause an error to be output + // saying the method could not be resolved. + String input = + "{% set a, b = {}, [] %}{% macro a.foo()%} 1-{{ b.bar() }}. {% endmacro %} {{ a.foo() }}"; + + RenderResult renderResult = new Jinjava() + .renderForResult(input, ImmutableMap.of("deferred", DeferredValue.instance())); + assertThat(renderResult.getOutput().trim()).isEqualTo("1-."); + // Does not contain an error about 'a.foo()' being unknown. + assertThat(renderResult.getErrors()).hasSize(1); + } + @Test public void itThrowsFatalErrors() { interpreter.getContext().setThrowInterpreterErrors(true);