Skip to content

Commit

Permalink
🐛 Do not automatically freeze SearchResult
Browse files Browse the repository at this point in the history
This was backward incompatible with existing usage of search results:
* Fixes #262
  • Loading branch information
nevans committed Feb 4, 2024
1 parent 153e69f commit a40b9df
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
8 changes: 2 additions & 6 deletions lib/net/imap/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class IMAP
# For backward compatibility, SearchResult inherits from Array.
class SearchResult < Array

# Returns a frozen SearchResult populated with the given +seq_nums+.
# Returns a SearchResult populated with the given +seq_nums+.
#
# Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
# # => Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
Expand All @@ -22,19 +22,15 @@ def self.[](*seq_nums, modseq: nil)
# §3.1.6]}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.1.6].
attr_reader :modseq

# Returns a frozen SearchResult populated with the given +seq_nums+.
# Returns a SearchResult populated with the given +seq_nums+.
#
# Net::IMAP::SearchResult.new([1, 3, 5], modseq: 9)
# # => Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
def initialize(seq_nums, modseq: nil)
super(seq_nums.to_ary.map { Integer _1 })
@modseq = Integer modseq if modseq
freeze
end

# Returns a frozen copy of +other+.
def initialize_copy(other); super; freeze end

# Returns whether +other+ is a SearchResult with the same values and the
# same #modseq. The order of numbers is irrelevant.
#
Expand Down
8 changes: 0 additions & 8 deletions test/net/imap/test_search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
class SearchDataTests < Test::Unit::TestCase
SearchResult = Net::IMAP::SearchResult

test "#frozen?" do
assert SearchResult.new([1, 3, 5]).frozen?
assert SearchResult[1, 3, 5].frozen?
assert SearchResult[1, 3, 5, modseq: 9].frozen?
assert SearchResult[1, 3, 5, modseq: 9].clone.frozen?
assert SearchResult[1, 3, 5, modseq: 9].dup.dup.frozen?
end

test "#modseq" do
assert_nil SearchResult[12, 34].modseq
assert_equal 123_456_789, SearchResult[12, 34, modseq: 123_456_789].modseq
Expand Down

0 comments on commit a40b9df

Please sign in to comment.