From 0a82efb1ecf38fb245fa77ee936cdfb3009ad002 Mon Sep 17 00:00:00 2001 From: Aaron Segal Date: Tue, 7 Nov 2023 13:33:31 -0500 Subject: [PATCH] Calls new render limit method from filter --- .../hubspot/jinjava/interpret/JinjavaInterpreter.java | 11 ++++++++--- .../com/hubspot/jinjava/lib/filter/RenderFilter.java | 11 ++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java index bc5c51ee1..d46568fc2 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java +++ b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java @@ -75,6 +75,8 @@ public class JinjavaInterpreter implements PyishSerializable { public static final String IGNORED_OUTPUT_FROM_EXTENDS_NOTE = "ignored_output_from_extends"; + public static final long NO_LIMIT = -1; + private final Multimap blocks = ArrayListMultimap.create(); private final LinkedList extendParentRoots = new LinkedList<>(); private final Map revertibleObjects = new HashMap<>(); @@ -94,7 +96,6 @@ public class JinjavaInterpreter implements PyishSerializable { private final Set errorSet = new HashSet<>(); private static final int MAX_ERROR_SIZE = 100; - private static final long NO_LIMIT = -1; public JinjavaInterpreter( Jinjava application, @@ -260,7 +261,11 @@ public String renderFlat(String template) { * @return rendered result */ public String render(String template) { - return render(parse(template), true); + return render(template, NO_LIMIT); + } + + public String render(String template, long renderLimit) { + return render(parse(template), true, renderLimit); } /** @@ -287,7 +292,7 @@ public String render(Node root, boolean processExtendRoots) { } /** - * Rendee the given root node to a certain limit, processing extend parents. + * Render the given root node to a certain limit, processing extend parents. * @param root * node to render * @param renderLimit diff --git a/src/main/java/com/hubspot/jinjava/lib/filter/RenderFilter.java b/src/main/java/com/hubspot/jinjava/lib/filter/RenderFilter.java index 63dd8225c..1a2809e5a 100644 --- a/src/main/java/com/hubspot/jinjava/lib/filter/RenderFilter.java +++ b/src/main/java/com/hubspot/jinjava/lib/filter/RenderFilter.java @@ -5,6 +5,7 @@ import com.hubspot.jinjava.doc.annotations.JinjavaSnippet; import com.hubspot.jinjava.interpret.JinjavaInterpreter; import java.util.Objects; +import org.apache.commons.lang3.math.NumberUtils; @JinjavaDoc( value = "Renders a template string early to be used by other filters and functions", @@ -25,11 +26,11 @@ public String getName() { @Override public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { if (args.length > 0) { - /* - This means a render limit length has been provided. - Here we begin a left to right render where we add to an HTML string until the length reaches a certain limit. - */ - return interpreter.render(Objects.toString(var)); + String firstArg = args[0]; + return interpreter.render( + Objects.toString(var), + NumberUtils.toLong(firstArg, JinjavaInterpreter.NO_LIMIT) + ); } return interpreter.render(Objects.toString(var)); }