Repository navigation
fix(go): split(none, n) maxsplit handling like Rust - #1003
Merged
Merged
Conversation
splitWhitespaceN only checked the split limit after appending a word, so split(none, 0) still split once: "a b c"|split(none, 0) gave ['a', 'b c'] instead of ['a b c']. When looking for the start of the rest it also read single bytes as runes, so multi-byte whitespace such as a non-breaking space stayed at the start of the rest. It now follows Python's str.split(None, maxsplit): skip leading whitespace, take at most maxsplit words, and return the rest with its trailing whitespace.
mitsuhiko
force-pushed
the
fix/go-split-maxsplit
branch
from
November 5, 2026 21:28
0f4bf7e to
97710f8
Compare
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.
Follow-up to #1001 for the Go port.
splitWhitespaceN(called withn = maxsplit + 1) only checked the split limit after appending a word, sosplit(none, 0)still split once. When looking for the start of the rest it also indexed bytes and converted them to runes, so multi-byte whitespace such as a non-breaking space was kept at the start of the rest:{{ "a b c"|split(none, 0) }}['a', 'b c']['a b c']{{ " a b c "|split(none, 0) }}['a', 'b c ']['a b c ']{{ "a b"|split(none, 1) }}['a', ' b']['a', 'b'](The "before" values are what the new test rows report on current
main; see the CI link below.)It now follows Python's
str.split(None, maxsplit): skip leading whitespace, take at mostmaxsplitwords, and return the rest with its trailing whitespace. The existingsplit-n-wscases (e.g." foo bar baz "|split(none, 1)→['foo', 'bar baz ']) and thestrings.Fieldspath for no or negativemaxsplitare unchanged. Added the three rows above toTestFiltersRejectUnsupportedValuesLikeRustand a changelog entry.I ran CI on my fork:
main): the three new rows fail inTestFiltersRejectUnsupportedValuesLikeRustwith the values above. https://github.com/ChandraChaan/minijinja/actions/runs/41539369037