Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/hubspot/jinjava/lib/tag/CallTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String getName() {
public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) {
String macroExpr = "{{" + tagNode.getHelpers().trim() + "}}";

try (InterpreterScopeClosable c = interpreter.enterScope()) {
try (InterpreterScopeClosable c = interpreter.enterNonStackingScope()) {
LinkedHashMap<String, Object> args = new LinkedHashMap<>();
MacroFunction caller = new MacroFunction(
tagNode.getChildren(),
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/hubspot/jinjava/lib/tag/CallTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import com.google.common.io.Resources;
import com.hubspot.jinjava.BaseInterpretingTest;
import com.hubspot.jinjava.Jinjava;
import com.hubspot.jinjava.JinjavaConfig;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.jsoup.Jsoup;
Expand All @@ -20,6 +23,28 @@ public void testSimpleFn() {
.isEqualTo("This is a simple dialog rendered by using a macro and a call block.");
}

@Test
public void itDoesNotDoubleCountCallTagTowardsDepth() throws IOException {
interpreter =
new Jinjava(
JinjavaConfig
.newBuilder()
.withEnableRecursiveMacroCalls(true)
.withMaxMacroRecursionDepth(6) // There are 3 call tags, but a total of 6 "macro" calls happening in this file as each call to `caller()` counts too
.build()
)
.newInterpreter();
JinjavaInterpreter.pushCurrent(interpreter);

try {
String template = fixture("multiple");
interpreter.render(template);
assertThat(interpreter.getErrorsCopy()).isEmpty();
} finally {
JinjavaInterpreter.popCurrent();
}
}

private String fixture(String name) {
try {
return Resources.toString(
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/tags/calltag/multiple.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% macro test1() %}1{{ caller() }}{% endmacro %}
{% macro test2() %}2{{ caller() }}{% endmacro %}
{% macro test3() %}3{{ caller() }}{% endmacro %}
{% call test1() %}{% call test2() %}{% call test3() %}{% endcall %}{% endcall %}{% endcall %}
Loading