From 6a7a07c93a6155c8fd1369aae655bcc338ff0650 Mon Sep 17 00:00:00 2001 From: nagibatorz Date: Fri, 6 Nov 2026 20:08:24 -0800 Subject: [PATCH 1/2] test: cover offset: continue after a negative offset for #2132 --- test/integration/tags/for_tag_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 36510eeab..0b54e1fda 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -228,6 +228,20 @@ def test_pause_resume_big_offset assert_template_result(expected, markup, assigns) end + def test_pause_resume_after_negative_offset + assigns = { 'array' => { 'items' => [1, 2, 3] } } + assert_template_result( + '1|23', + '{%for i in array.items offset: -1 limit: 2 %}{{i}}{%endfor%}|{%for i in array.items offset:continue %}{{i}}{%endfor%}', + assigns + ) + assert_template_result( + '123|', + '{%for i in array.items offset: -1 %}{{i}}{%endfor%}|{%for i in array.items offset:continue %}{{i}}{%endfor%}', + assigns + ) + end + def test_for_with_break assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } } From 2b33dd874074ee323221dd2f991d8f332e95ba52 Mon Sep 17 00:00:00 2001 From: nagibatorz Date: Fri, 6 Nov 2026 20:08:30 -0800 Subject: [PATCH 2/2] fix: clamp for-loop continuation cursor after a negative offset Fixes #2132 --- lib/liquid/tags/for.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index 598d7bee5..879d752aa 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -143,7 +143,11 @@ def collection_segment(context) ) segment.reverse! if @reversed - offsets[@name] = from + segment.length + # The slice is clamped to the start of the collection, so a negative + # offset still renders from the first item. Clamp the stored cursor + # the same way, otherwise `offset: continue` resumes from + # `from + segment.length` and replays items (or skips past the end). + offsets[@name] = [from, 0].max + segment.length segment end