Skip to content
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

Merged
merged 4 commits into from
Aug 15, 2017
Merged

Prevent recursion in Jinjava. #142

merged 4 commits into from
Aug 15, 2017

Conversation

hs-lsong
Copy link
Collaborator

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.

@hs-lsong hs-lsong requested a review from boulter August 14, 2017 21:27
return renderStack.pop();
}

public Stack getRenderStack() {
Copy link
Contributor

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();
Copy link
Contributor

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) %}" +
Copy link
Contributor

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 {
Copy link
Collaborator Author

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() {
Copy link
Collaborator Author

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.

@hs-lsong hs-lsong merged commit 1d8ff37 into master Aug 15, 2017
@hs-lsong hs-lsong deleted the prevent-recursion branch August 15, 2017 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants