Skip to content

Commit 254d5fc

Browse files
committed
Added safer limit clamping function
1 parent 4e2e4a1 commit 254d5fc

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ public String render(Node root, boolean processExtendRoots) {
301301
* @return rendered result
302302
*/
303303
private String render(Node root, boolean processExtendRoots, long renderLimit) {
304-
long safeRenderSize = (config.getMaxOutputSize() == 0)
305-
? renderLimit
306-
: Math.min(renderLimit, config.getMaxOutputSize());
307-
OutputList output = new OutputList(safeRenderSize);
304+
OutputList output = new OutputList(clampOutputSizeSafely(renderLimit));
308305
for (Node node : root.getChildren()) {
309306
lineNumber = node.getLineNumber();
310307
position = node.getStartPosition();
@@ -927,6 +924,20 @@ private String getWrappedErrorMessage(
927924
}
928925
}
929926

927+
private long clampOutputSizeSafely(long providedLimit) {
928+
long configMaxOutput = config.getMaxOutputSize();
929+
930+
if (configMaxOutput == 0) {
931+
return providedLimit;
932+
}
933+
934+
if (providedLimit <= 0) {
935+
return configMaxOutput;
936+
}
937+
938+
return Math.min(providedLimit, configMaxOutput);
939+
}
940+
930941
@Override
931942
@SuppressWarnings("unchecked")
932943
public <T extends Appendable & CharSequence> T appendPyishString(T appendable)

0 commit comments

Comments
 (0)