Don't make new call stacks when interpreting a CallTag so that the max render depth is tracked properly by jasmith-hs · Pull Request #1229 · HubSpot/jinjava · GitHub
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
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