Skip to content

Commit

Permalink
Merge pull request #708 from HubSpot/property-resolved
Browse files Browse the repository at this point in the history
Set propertyResolved after evaluating the AbstractCallableMethod
  • Loading branch information
jasmith-hs authored Jul 13, 2021
2 parents 3c35fd9 + 03a0f0f commit 83c0b21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 83c0b21

Please sign in to comment.