Skip to content

Commit

Permalink
Using max output param to clamp outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
asegal-hs committed Nov 7, 2023
1 parent 87e6a0e commit baae46e
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class JinjavaInterpreter implements PyishSerializable {
private final Set<Integer> errorSet = new HashSet<>();

private static final int MAX_ERROR_SIZE = 100;
private static final long NO_LIMIT = -1;

public JinjavaInterpreter(
Jinjava application,
Expand Down Expand Up @@ -263,14 +264,38 @@ public String render(String template) {
}

/**
* Render the given root node, processing extend parents. Equivalent to render(root, true)
* Render the given root node, processing extend parents. Equivalent to render(root, true, -1)
*
* @param root
* node to render
* @return rendered result
*/
public String render(Node root) {
return render(root, true);
return render(root, true, NO_LIMIT);
}

/**
* Render the given root node with an option to process extend parents.
* Equivalent to render(root, processExtendRoots, -1).
* @param root
* node to render
* @param processExtendRoots
* @return
*/
public String render(Node root, boolean processExtendRoots) {
return render(root, processExtendRoots, NO_LIMIT);
}

/**
* Rendee the given root node to a certain limit, processing extend parents.
* @param root
* node to render
* @param renderLimit
* the number of characters in response text
* @return
*/
public String render(Node root, long renderLimit) {
return render(root, true, renderLimit);
}

/**
Expand All @@ -280,10 +305,15 @@ public String render(Node root) {
* node to render
* @param processExtendRoots
* if true, also render all extend parents
* @param renderLimit
* the number of characters the result may contain
* @return rendered result
*/
public String render(Node root, boolean processExtendRoots) {
OutputList output = new OutputList(config.getMaxOutputSize());
public String render(Node root, boolean processExtendRoots, long renderLimit) {
long maxOutput = (renderLimit == NO_LIMIT)
? config.getMaxOutputSize()
: (Math.min(renderLimit, config.getMaxOutputSize()));
OutputList output = new OutputList(maxOutput);

for (Node node : root.getChildren()) {
lineNumber = node.getLineNumber();
Expand Down

0 comments on commit baae46e

Please sign in to comment.