Skip to content

Commit

Permalink
add rangeLimit to JinjavaConfig (minor refactor based on PR comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
ylacaute committed Apr 29, 2021
1 parent d6efa02 commit 53cf9c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
13 changes: 3 additions & 10 deletions src/main/java/com/hubspot/jinjava/lib/fn/Functions.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.hubspot.jinjava.lib.fn;

import static com.hubspot.jinjava.interpret.JinjavaInterpreter.getCurrent;
import static com.hubspot.jinjava.util.Logging.ENGINE_LOG;
import static java.util.Objects.requireNonNull;

import com.google.common.collect.Lists;
import com.hubspot.jinjava.JinjavaConfig;
Expand Down Expand Up @@ -52,7 +50,7 @@ public class Functions {
}
)
public static String renderSuperBlock() {
JinjavaInterpreter interpreter = getCurrent();
JinjavaInterpreter interpreter = JinjavaInterpreter.getCurrent();
LengthLimitingStringBuilder result = new LengthLimitingStringBuilder(
interpreter.getConfig().getMaxOutputSize()
);
Expand Down Expand Up @@ -389,20 +387,15 @@ public static int movePointerToJustBeforeLastWord(int pointer, String s) {
"The third parameter specifies the step increment. All values can be negative. Impossible ranges will return an empty list. " +
"Ranges can generate a maximum of " +
DEFAULT_RANGE_LIMIT +
" values by default, but this integer value is configurable.",
" values.",
params = {
@JinjavaParam(value = "start", type = "number", defaultValue = "0"),
@JinjavaParam(value = "end", type = "number"),
@JinjavaParam(value = "step", type = "number", defaultValue = "1")
}
)
public static List<Integer> range(Object arg1, Object... args) {
int rangeLimit = requireNonNull(
JinjavaInterpreter.getCurrent(),
"No JinjavaInterpreter instance available to use range function"
)
.getConfig()
.getRangeLimit();
int rangeLimit = JinjavaInterpreter.getCurrent().getConfig().getRangeLimit();
List<Integer> result = new ArrayList<>();

int start = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public void afterEach() {
@Test
public void interpreterInstanceIsMandatory() {
JinjavaInterpreter.popCurrent();
assertThatThrownBy(() -> Functions.range(1))
.isInstanceOf(NullPointerException.class)
.hasMessage("No JinjavaInterpreter instance available to use range function");
assertThatThrownBy(() -> Functions.range(1)).isInstanceOf(NullPointerException.class);
}

@Test
Expand Down

0 comments on commit 53cf9c1

Please sign in to comment.