Repository navigation
fix(for, tablerow): treat a negative offset or limit like Ruby Liquid - #1012
Merged
Merged
Conversation
harttle
requested changes
Nov 25, 2026
harttle
approved these changes
Nov 25, 2026
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.
Array.prototype.slicecounts a negative index from the end, so a negativeoffsetorlimiton{% for %}and{% tablerow %}dropped items from the wrong end:{% for i in (0..3) offset: -2 %}{{ i }}{% endfor %} → "23" (Ruby Liquid: "0123") {% for i in (0..3) offset: -2 limit: 3 %}{{ i }}{% endfor %} → "23" (Ruby Liquid: "0") {% for i in (0..5) offset: 1 limit: -1 %}{{ i }}{% endfor %} → "12" (Ruby Liquid: "") {% tablerow i in (1..3) offset: -1 %}{{ i }}{% endtablerow %} → one cell "3" (Ruby Liquid: 1, 2, 3)Ruby Liquid keeps the items whose index is in
[offset, offset + limit)(Utils.slice_collection), so a negative offset skips nothing but still shortens the limit, and a negative limit leaves nothing. Both tags now clamp the slice bounds at 0 and count the limit from the raw offset.offset: continueafter a negative offset resumes atoffset + length, same as before and same as Ruby.These are the five
tags/fornegative offset/limit cases from jg-rp/golden-liquid listed in #1004 (range loop, negative offset,..., continue,..., limit,offset, negative limit,negative offset, negative limit); they pass now and the other goldenfor/tablerowresults are unchanged. The two tablerow golden cases still differ only by the newlines Ruby writes after<tr>.Tests: 7 new cases in
for.spec.tsandtablerow.spec.tsfail on master and pass now.npm test(1782) passes with TZEtc/GMT,Asia/ShanghaiandAmerica/New_York;npm run lintpasses.