Repository navigation
Fix split(none, n) returning trailing whitespace - #1001
Merged
Merged
Conversation
splitn_whitespace remembered where the last split ended and returned everything after it once the input was exhausted. When the string ended in whitespace right after a word, that whitespace was returned as an extra item, so "a b "|split(none, 5) gave ["a", "b", " "] and " "|split(none, 0) gave [" "]. At the end of the input only a word that is still open (or the remainder after the last allowed split) is returned now.
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.
splitn_whitespaceremembered where the last split ended and, once the input was exhausted, returned everything after it. When the string ends in whitespace right after a word, that whitespace came back as an extra item, unlike Python and minijinja-go:{{ "a b "|split(none, 5)|list }}["a", "b", " "]["a", "b"]{{ "a "|split(none, 1)|list }}["a", " "]["a"]{{ " "|split(none, 0)|list }}[" "][]This also contradicts the filter's doc comment ("multiple spaces and empty strings will be removed from the result"), and applies to pycompat's
str.split, which calls this filter.At the end of the input it now returns only a word that is still open, or the remainder after the last allowed split, so
last_split_endis no longer needed. The remainder still keeps its trailing whitespace like Python ("a b "with 2 splits is["a", "b "]), and thesplit-n-wssnapshots are unchanged. Added cases totest_splitn_whitespaceand a changelog entry.I ran CI on my fork:
main):test_splitn_whitespacefails in the Rust test jobs (39 passed, 1 failed):left: ["a", "b", " "],right: ["a", "b"]. https://github.com/ChandraChaan/minijinja/actions/runs/41440539404I haven't changed the Go port here. It has a separate issue in the same feature (
split(none, 0)still splits once), which I can send separately.