-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent recursion in Jinjava. #142
Conversation
return renderStack.pop(); | ||
} | ||
|
||
public Stack getRenderStack() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we really want to protect the underlying stack from being modified outside the Context, then I think you just need to implement doesStackContain()
. Otherwise this allows total access to the stack contents.
"{{ allSpans(spans, '') }}" + | ||
""; | ||
Node node = new TreeParser(interpreter, jinja).buildTree(); | ||
assertThat(JinjavaInterpreter.getCurrent() == interpreter).isTrue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this line testing for?
|
||
@Test | ||
public void itPreventsRecursionForMacroWithVar() { | ||
String jinja = "{%- macro allSpans(spans) %}" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this example be simplified? It reflects the original issue, but I think the the test would be easier to understand if it the content of spans was smaller and it wasn't so specific to the original issue with spans, since it really could be a problem with any type of map.
@@ -77,7 +77,7 @@ public void itAvoidsInfiniteRecursionOfItself() throws Exception { | |||
} | |||
|
|||
@Test | |||
public void itNoRecursionHere() throws Exception { | |||
public void itDoesNotRescursivelyEvaluateExpressions() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, there is not recursion here.
@@ -158,7 +158,25 @@ public void itAllowsMacroRecursionWhenEnabledInConfiguration() throws IOExceptio | |||
} | |||
} | |||
|
|||
|
|||
@Test | |||
public void itPreventsRecursionForMacroWithVar() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this test is not necessary, since the recursion cases are tested in the ExpressionNodeTest. This is to confirm that the recursion happens even when macro is called.
Although we limit the rendering depth at 10, but that can still be large if the recursive expression has multiple self references. With this change, we still render the recursion once, then stop render is any further.