Fix implementation for slice filter#398
Merged
Merged
Conversation
liamrharwood
approved these changes
Feb 12, 2020
liamrharwood
left a comment
Contributor
There was a problem hiding this comment.
This looks good, just a couple suggestions.
Also, can we update the JinjavaDoc annotation to reflect the second argument?
| @@ -47,7 +51,30 @@ public Object filter(Object var, JinjavaInterpreter interpreter, String... args) | |||
| } | |||
|
|
|||
| int slices = NumberUtils.toInt(args[0], 3); | |||
Contributor
There was a problem hiding this comment.
Any reason we default to 3 here?
Collaborator
Author
There was a problem hiding this comment.
Ideally we would throw an error if args[0] wasn't provided, however we can't do that without breaking existing functionality. Somebody could be using a raw |slice out there.
|
|
||
| if (args.length > 1 && currentList != null) { | ||
| while (currentList.size() < slices) { | ||
| currentList.add(args[1]); |
Contributor
There was a problem hiding this comment.
nit: assign args[1] to something like fillWith for clarity
added 2 commits
February 12, 2020 15:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Slice filter was not implemented as according to spec. When doing
list|slice(3)we should not be padding non-divisible slices with null values. When usinglist|slice(3, 'value')we should pad non-divisible slices withvalue. https://jinja.palletsprojects.com/en/2.11.x/templates/#slice