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. |
boulter
left a comment
There was a problem hiding this comment.
Now, what should a reasonable limit be? :)
| } catch (MacroTagCycleException e) { | ||
|
|
||
| int maxDepth = interpreter.getConfig().getMaxMacroRecursionDepth(); | ||
| String message; |
|
|
||
| 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.
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
enableRecursiveMacroCallstotrueandmaxMacroRecursionDepthto a reasonable value to prevent a template from killing your thread due to stack overflows.