Add max string length to Jinjava config.#275
Conversation
Codecov Report
@@ Coverage Diff @@
## master #275 +/- ##
============================================
+ Coverage 72.19% 72.29% +0.09%
- Complexity 1475 1477 +2
============================================
Files 231 231
Lines 4571 4587 +16
Branches 731 732 +1
============================================
+ Hits 3300 3316 +16
Misses 1016 1016
Partials 255 255
Continue to review full report at Codecov.
|
| } catch (OutputTooBigException ex) { | ||
| interpreter.addError(new TemplateError(ErrorType.WARNING, | ||
| ErrorReason.OTHER, | ||
| ErrorItem.OTHER, |
| } | ||
| stringBuilder.append(Objects.toString(val, "")); | ||
| } catch (OutputTooBigException ex) { | ||
| interpreter.addError(new TemplateError(ErrorType.WARNING, |
There was a problem hiding this comment.
Not necessarily FATAL IMO since it will still output a string, just shorter than expected.
| } | ||
|
|
||
| vals.add(Objects.toString(val, "")); | ||
| try { |
There was a problem hiding this comment.
You can also simple sum the length of each string and compare to the limit. It may look simpler. Up to you.
There was a problem hiding this comment.
That's how the modified string builder works and throws the exception once the length > limit. I didn't see the need to duplicate the code we already have in there.
boulter
left a comment
There was a problem hiding this comment.
anywhere else we can apply this? ~ operator?
| } | ||
|
|
||
| @Test | ||
| public void itLimitsString() { |
|
Yes I am planning adding this elsewhere once the approach is approved. |
|
|
||
| RenderResult result = jinjava.renderForResult("{{ [1, 2, 3, 4, 5]|join('|') }}", new HashMap<String, Object>()); | ||
| assertThat(result.getOutput()).isEqualTo("1|2|3"); | ||
| assertThat(result.getErrors().size()).isEqualTo(1); |
There was a problem hiding this comment.
it would be good to verify that error is what you expect.
Adds a max string length to the config. As a test, I have used this setting to limit the output of the
Joinfilter, however it can be used in other filters as well if the approach looks fine.