Skip to content

Commit 299adf9

Browse files
committed
Don't make new call stacks when interpreting a CallTag so that the max
render depth is tracked properly
1 parent e94fa9a commit 299adf9

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/main/java/com/hubspot/jinjava/lib/tag/CallTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public String getName() {
6767
public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) {
6868
String macroExpr = "{{" + tagNode.getHelpers().trim() + "}}";
6969

70-
try (InterpreterScopeClosable c = interpreter.enterScope()) {
70+
try (InterpreterScopeClosable c = interpreter.enterNonStackingScope()) {
7171
LinkedHashMap<String, Object> args = new LinkedHashMap<>();
7272
MacroFunction caller = new MacroFunction(
7373
tagNode.getChildren(),

src/test/java/com/hubspot/jinjava/lib/tag/CallTagTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

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

26+
@Test
27+
public void itDoesNotDoubleCountCallTagTowardsDepth() throws IOException {
28+
interpreter =
29+
new Jinjava(
30+
JinjavaConfig
31+
.newBuilder()
32+
.withEnableRecursiveMacroCalls(true)
33+
.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
34+
.build()
35+
)
36+
.newInterpreter();
37+
JinjavaInterpreter.pushCurrent(interpreter);
38+
39+
try {
40+
String template = fixture("multiple");
41+
interpreter.render(template);
42+
assertThat(interpreter.getErrorsCopy()).isEmpty();
43+
} finally {
44+
JinjavaInterpreter.popCurrent();
45+
}
46+
}
47+
2348
private String fixture(String name) {
2449
try {
2550
return Resources.toString(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% macro test1() %}1{{ caller() }}{% endmacro %}
2+
{% macro test2() %}2{{ caller() }}{% endmacro %}
3+
{% macro test3() %}3{{ caller() }}{% endmacro %}
4+
{% call test1() %}{% call test2() %}{% call test3() %}{% endcall %}{% endcall %}{% endcall %}

0 commit comments

Comments
 (0)