From 37906b559774136d65667a0633fa95f372aef623 Mon Sep 17 00:00:00 2001 From: nick evans Date: Mon, 28 Sep 2026 09:40:37 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`SequenceSet#slice`=20when?= =?UTF-8?q?=20starting=20at=20"*"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the starting index points to "*", the `min <= max` comparison fails and an exception is raised. Without changing the basic `#slice_range` structure and algorithm, the simplest fix is to use the internal integers for `min` and `max`, which will always be comparable. --- lib/net/imap/sequence_set.rb | 8 +++----- test/net/imap/test_sequence_set.rb | 11 +---------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/net/imap/sequence_set.rb b/lib/net/imap/sequence_set.rb index 28a51fc9c..29c59e800 100644 --- a/lib/net/imap/sequence_set.rb +++ b/lib/net/imap/sequence_set.rb @@ -2434,11 +2434,9 @@ def slice_range(range) end if (first * last).positive? && last < first remain_frozen_empty - elsif (min = at(first)) - max = at(last) - max = :* if max.nil? - if max == :* then self & (min..) - elsif min <= max then self & (min..max) + elsif (min = sorted_set_num_at(first)) + max = sorted_set_num_at(last) || STAR_INT + if min <= max then intersection export_minmax_entry [min, max] else remain_frozen_empty end end diff --git a/test/net/imap/test_sequence_set.rb b/test/net/imap/test_sequence_set.rb index b4a10ea28..bd3801076 100644 --- a/test/net/imap/test_sequence_set.rb +++ b/test/net/imap/test_sequence_set.rb @@ -496,15 +496,6 @@ def pend_slice_lomax(set, start, actual) assert_equal set[start..], actual end - def pend_slice_star(expected, &) - pend_slice_bug "don't crash when min == :*" do - assert_same expected, yield - end - assert_raise_with_message(ArgumentError, - /\Acomparison of Symbol with \d+ /, - &) - end - def pend_slice_nil(actual) pend_slice_bug "return nil for invalid slice start index" do assert_nil actual @@ -616,7 +607,7 @@ def pend_slice_zero_len(&) assert_same SequenceSet.empty, set[-100.. 99] # i.e: 100.. 99 assert_same SequenceSet.empty, set[ -1... 199] # i.e: 199...199 assert_same SequenceSet.empty, set[ -1.. 198] # i.e: 199...198 - pend_slice_star SequenceSet.empty do SequenceSet.full[-1..0] end + assert_same SequenceSet.empty, SequenceSet.full[-1..0] assert_same SequenceSet.empty, SequenceSet.full[-1...0] end