diff --git a/lib/net/imap/sequence_set.rb b/lib/net/imap/sequence_set.rb index cb3e41a3..5f10a187 100644 --- a/lib/net/imap/sequence_set.rb +++ b/lib/net/imap/sequence_set.rb @@ -1342,8 +1342,8 @@ def tuple_add(tuple) modifying! min, max = tuple lower, lower_idx = tuple_gte_with_index(min - 1) - if lower.nil? then tuples << tuple - elsif (max + 1) < lower.first then tuples.insert(lower_idx, tuple) + if lower.nil? then tuples << [min, max] + elsif (max + 1) < lower.first then tuples.insert(lower_idx, [min, max]) else tuple_coalesce(lower, lower_idx, min, max) end end diff --git a/test/net/imap/test_sequence_set.rb b/test/net/imap/test_sequence_set.rb index e2f1ce7e..fa91288e 100644 --- a/test/net/imap/test_sequence_set.rb +++ b/test/net/imap/test_sequence_set.rb @@ -359,6 +359,11 @@ def obj.to_sequence_set; 192_168.001_255 end assert_equal seqset["1:3,5,7:9"], seqset["1,3,5,7:8"].merge(seqset["2,8:9"]) assert_equal seqset["1:*"], seqset["5:*"].merge(1..4) assert_equal seqset["1:5"], seqset["1,3,5"].merge(seqset["2,4"]) + # when merging frozen SequenceSet + set = SequenceSet.new + set.merge SequenceSet[1, 3, 5] + set.merge SequenceSet[2..33] + assert_equal seqset[1..33], set end test "set - other" do