Skip to content

Commit

Permalink
Added safer limit clamping function
Browse files Browse the repository at this point in the history
  • Loading branch information
asegal-hs committed Nov 20, 2023
1 parent 4e2e4a1 commit 254d5fc
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 extends Appendable & CharSequence> T appendPyishString(T appendable)
Expand Down

0 comments on commit 254d5fc

Please sign in to comment.