-
Notifications
You must be signed in to change notification settings - Fork 171
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
Limit output size #108
Limit output size #108
Changes from 3 commits
d99a9a0
b9c7cd2
fdcfb35
26083b8
6347b41
026d006
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.hubspot.jinjava.interpret; | ||
|
||
public class OutputTooBigException extends RuntimeException { | ||
|
||
private final long size; | ||
|
||
public OutputTooBigException(long size) { | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("%d byte output rendered", size); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,25 @@ | |
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import com.hubspot.jinjava.interpret.OutputTooBigException; | ||
|
||
public class OutputList { | ||
|
||
private final List<OutputNode> nodes = new LinkedList<>(); | ||
private final List<BlockPlaceholderOutputNode> blocks = new LinkedList<>(); | ||
private long maxOutputSize; | ||
|
||
public OutputList(long maxOutputSize) { | ||
|
||
this.maxOutputSize = maxOutputSize; | ||
} | ||
|
||
public void addNode(OutputNode node) { | ||
|
||
if (maxOutputSize > 0 && node.getSize() > maxOutputSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this only check the size of this node against the max? What if we're adding a large number of very small nodes? Just pushed a test that shows what I mean. If this is only intended to limit the size of individual nodes, I think we should change the name of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be fixed now |
||
throw new OutputTooBigException(node.getSize()); | ||
} | ||
|
||
nodes.add(node); | ||
|
||
if (node instanceof BlockPlaceholderOutputNode) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ public interface OutputNode { | |
|
||
String getValue(); | ||
|
||
long getSize(); | ||
|
||
} |
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: why the extra line here?