Skip to content

Commit 37906b5

Browse files
committed
🐛 Fix SequenceSet#slice when starting at "*"
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.
1 parent 4bf5bb4 commit 37906b5

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

‎lib/net/imap/sequence_set.rb‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,11 +2434,9 @@ def slice_range(range)
24342434
end
24352435
if (first * last).positive? && last < first
24362436
remain_frozen_empty
2437-
elsif (min = at(first))
2438-
max = at(last)
2439-
max = :* if max.nil?
2440-
if max == :* then self & (min..)
2441-
elsif min <= max then self & (min..max)
2437+
elsif (min = sorted_set_num_at(first))
2438+
max = sorted_set_num_at(last) || STAR_INT
2439+
if min <= max then intersection export_minmax_entry [min, max]
24422440
else remain_frozen_empty
24432441
end
24442442
end

‎test/net/imap/test_sequence_set.rb‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,6 @@ def pend_slice_lomax(set, start, actual)
496496
assert_equal set[start..], actual
497497
end
498498

499-
def pend_slice_star(expected, &)
500-
pend_slice_bug "don't crash when min == :*" do
501-
assert_same expected, yield
502-
end
503-
assert_raise_with_message(ArgumentError,
504-
/\Acomparison of Symbol with \d+ /,
505-
&)
506-
end
507-
508499
def pend_slice_nil(actual)
509500
pend_slice_bug "return nil for invalid slice start index" do
510501
assert_nil actual
@@ -616,7 +607,7 @@ def pend_slice_zero_len(&)
616607
assert_same SequenceSet.empty, set[-100.. 99] # i.e: 100.. 99
617608
assert_same SequenceSet.empty, set[ -1... 199] # i.e: 199...199
618609
assert_same SequenceSet.empty, set[ -1.. 198] # i.e: 199...198
619-
pend_slice_star SequenceSet.empty do SequenceSet.full[-1..0] end
610+
assert_same SequenceSet.empty, SequenceSet.full[-1..0]
620611
assert_same SequenceSet.empty, SequenceSet.full[-1...0]
621612
end
622613

0 commit comments

Comments
 (0)