Skip to content

Commit 16e60a4

Browse files
committed
🐛 Fix SequenceSet#slice with range (start...0)
The bug was that exclusive ranges ending in zero would be converted to end on `-1`, which would be interpretted as the last value in the range.
1 parent c362be8 commit 16e60a4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/net/imap/sequence_set.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,10 @@ def slice_length(start, length)
12411241
def slice_range(range)
12421242
first = range.begin || 0
12431243
last = range.end || -1
1244-
last -= 1 if range.exclude_end? && range.end && last != STAR_INT
1244+
if range.exclude_end?
1245+
return SequenceSet.empty if last.zero?
1246+
last -= 1 if range.end && last != STAR_INT
1247+
end
12451248
if (first * last).positive? && last < first
12461249
SequenceSet.empty
12471250
elsif (min = at(first))

test/net/imap/test_sequence_set.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def obj.to_sequence_set; 192_168.001_255 end
289289
assert_equal SequenceSet.empty, SequenceSet[1..100][-50..-60]
290290
assert_equal SequenceSet.empty, SequenceSet[1..100][-10..10]
291291
assert_equal SequenceSet.empty, SequenceSet[1..100][60..-60]
292+
assert_equal SequenceSet.empty, SequenceSet[1..100][10...0]
293+
assert_equal SequenceSet.empty, SequenceSet[1..100][0...0]
292294
assert_nil SequenceSet.empty[2..4]
293295
assert_nil SequenceSet[101..200][1000..1060]
294296
assert_nil SequenceSet[101..200][-1000..-60]

0 commit comments

Comments
 (0)