-
Notifications
You must be signed in to change notification settings - Fork 168
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
Allow ability to set a max recursion depth in config. #308
Conversation
Codecov Report
@@ Coverage Diff @@
## master #308 +/- ##
============================================
- Coverage 71.58% 70.67% -0.91%
- Complexity 1553 1559 +6
============================================
Files 239 239
Lines 4863 4945 +82
Branches 787 801 +14
============================================
+ Hits 3481 3495 +14
- Misses 1097 1165 +68
Partials 285 285
Continue to review full report at Codecov.
|
The need for this is to be able to build nesting structures like site menus without resolving to copying and pasting a macro n times to support a menu with depth n. It is still dangerous to allow infinite recursion so we can set this max value to something reasonable like 10-20. |
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.
Now, what should a reasonable limit be? :)
} else { | ||
macroStack.push(getName(), -1, -1); | ||
} | ||
} catch (MacroTagCycleException e) { | ||
|
||
int maxDepth = interpreter.getConfig().getMaxMacroRecursionDepth(); | ||
String message; |
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.
nit: tertiary statement
} | ||
|
||
public JinjavaConfig(Charset charset, Locale locale, ZoneId timeZone, int maxRenderDepth) { | ||
this(charset, locale, timeZone, maxRenderDepth, new HashMap<>(), false, false, true, false, false, 0, true, RandomNumberGeneratorStrategy.THREAD_LOCAL, false, 0); | ||
this(charset, locale, timeZone, maxRenderDepth, new HashMap<>(), false, false, true, false, 0, false, 0, true, RandomNumberGeneratorStrategy.THREAD_LOCAL, false, 0); |
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.
might be nigh time for a builder here.
Java 8 stack frame size in the worst case is going to be about 1kb so I was thinking 50 as a limit. |
I think 10 or 20 would be more reasonable since you could possibly interleave other functions recursively. |
I think 20 would be good. This is total macro stack size but I think it is unlikely that someone currently has a template that calls 20 nested macros. |
especially on HubSpot, where nesting macros previously didn't actually work. |
This is a middle ground option for #91. You can now set
enableRecursiveMacroCalls
totrue
andmaxMacroRecursionDepth
to a reasonable value to prevent a template from killing your thread due to stack overflows.