Skip to content

Commit f294f9c

Browse files
committed
🐛 Fix SearchResult#== for LHS with no modseq
If `#modseq` wasn't set, `SearchResult#==` wouldn't check rhs's modseq.
1 parent cd154d8 commit f294f9c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/net/imap/search_result.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ def initialize(seq_nums, modseq: nil)
6060
# [3, 5, 7] == Net::IMAP::SearchResult[3, 5, 7, modseq: 99] # => true
6161
#
6262
def ==(other)
63-
(modseq ?
64-
other.is_a?(self.class) && modseq == other.modseq :
65-
other.is_a?(Array)) &&
63+
other.is_a?(Array) &&
64+
modseq == (other.modseq if other.respond_to?(:modseq)) &&
6665
size == other.size &&
6766
sort == other.sort
6867
end

test/net/imap/test_search_result.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class SearchDataTests < Test::Unit::TestCase
2424
sorted = SearchResult[2, 4, 99, 2048, modseq: 99_999]
2525
assert_equal unsorted, sorted
2626
assert_equal sorted, unsorted
27+
28+
nomodseq = SearchResult[2, 4, 99, 2048]
29+
refute_equal sorted, nomodseq
30+
refute_equal nomodseq, sorted
2731
end
2832

2933
test "SearchResult[*nz_numbers] == Array[*nz_numbers]" do

0 commit comments

Comments
 (0)