diff --git a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java index 1fb6a5e94..1bb10fad0 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java +++ b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java @@ -301,10 +301,7 @@ public String render(Node root, boolean processExtendRoots) { * @return rendered result */ private String render(Node root, boolean processExtendRoots, long renderLimit) { - long safeRenderSize = (config.getMaxOutputSize() == 0) - ? renderLimit - : Math.min(renderLimit, config.getMaxOutputSize()); - OutputList output = new OutputList(safeRenderSize); + OutputList output = new OutputList(clampOutputSizeSafely(renderLimit)); for (Node node : root.getChildren()) { lineNumber = node.getLineNumber(); position = node.getStartPosition(); @@ -927,6 +924,20 @@ private String getWrappedErrorMessage( } } + private long clampOutputSizeSafely(long providedLimit) { + long configMaxOutput = config.getMaxOutputSize(); + + if (configMaxOutput == 0) { + return providedLimit; + } + + if (providedLimit <= 0) { + return configMaxOutput; + } + + return Math.min(providedLimit, configMaxOutput); + } + @Override @SuppressWarnings("unchecked") public T appendPyishString(T appendable)