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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.hubspot.jinjava.objects.serialization.PyishSerializable;
import com.hubspot.jinjava.random.ConstantZeroRandomNumberGenerator;
import com.hubspot.jinjava.random.DeferredRandomNumberGenerator;
import com.hubspot.jinjava.tree.ExpressionNode;
import com.hubspot.jinjava.tree.Node;
import com.hubspot.jinjava.tree.TagNode;
import com.hubspot.jinjava.tree.TreeParser;
Expand Down Expand Up @@ -259,7 +260,7 @@ public String render(Node root, boolean processExtendRoots) {
position = node.getStartPosition();
String renderStr = node.getMaster().getImage();
try {
if (context.doesRenderStackContain(renderStr)) {
if (node instanceof ExpressionNode && context.doesRenderStackContain(renderStr)) {
// This is a circular rendering. Stop rendering it here.
addError(
new TemplateError(
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/hubspot/jinjava/tree/ExpressionNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ public void itAvoidsInfiniteRecursionWhenVarsContainBraceBlocks() throws Excepti
assertThat(node.render(interpreter).toString()).isEqualTo("hello {{ place }}");
}

@Test
public void itAllowsNestedTagExpressions() throws Exception {
context.put("myvar", "{% if true %}{{ place }}{% endif %}");
context.put("place", "{% if true %}Hello{% endif %}");

ExpressionNode node = fixture("simplevar");
assertThat(node.render(interpreter).toString()).isEqualTo("Hello");
}

@Test
public void itAvoidsInfiniteRecursionWhenVarsAreInIfBlocks() throws Exception {
context.put("myvar", "{% if true %}{{ place }}{% endif %}");
context.put("place", "{% if true %}{{ myvar }}{% endif %}");

ExpressionNode node = fixture("simplevar");
assertThat(node.render(interpreter).toString())
.isEqualTo("{% if true %}{{ myvar }}{% endif %}");
}

@Test
public void itDoesNotRescursivelyEvaluateExpressionsOfSelf() throws Exception {
context.put("myvar", "hello {{myvar}}");
Expand Down