-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,7 +158,27 @@ public void itAllowsMacroRecursionWhenEnabledInConfiguration() throws IOExceptio | |
} | ||
} | ||
|
||
|
||
@Test | ||
public void itPreventsRecursionForMacroWithVar() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
String jinja = "{%- macro allSpans(spans) %}" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"{%- for span in spans %}" + | ||
"{{ span.tag }}" + | ||
"{%- endfor %}" + | ||
"{%- endmacro %}" + | ||
"{%- set spans = {" + | ||
" 'html_1' : {" + | ||
" 'tag' : 'html {{ selector }}'," + | ||
" 'span' : 12" + | ||
" }" + | ||
"} %}" + | ||
"{% set selector='{{spans}}' %}" + | ||
"{{ 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 commentThe reason will be displayed to describe this comment to others. Learn more. what is this line testing for? |
||
assertThat(interpreter.render(node)).isEqualTo( | ||
"html {html_1={tag=html {html_1={tag=html {{ selector }}, span=12}}, span=12}}"); | ||
} | ||
|
||
private Node snippet(String jinja) { | ||
return new TreeParser(interpreter, jinja).buildTree().getChildren().getFirst(); | ||
|
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.