Skip to content

Commit

Permalink
🐛 Fix SequenceSet#append when @string is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Jan 17, 2025
1 parent 0eb4390 commit 4c9b1a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/net/imap/sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,9 @@ def append(object)
modifying!
tuple = input_to_tuple object
entry = tuple_to_str tuple
string unless empty? # write @string before tuple_add
tuple_add tuple
@string = -(string ? "#{@string},#{entry}" : entry)
@string = -(@string ? "#{@string},#{entry}" : entry)
self
end

Expand Down
8 changes: 8 additions & 0 deletions test/net/imap/test_sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ def obj.to_sequence_set; 192_168.001_255 end
assert_equal "1:6,4:9", SequenceSet.new("1:6").append("4:9").string
assert_equal "1:4,5:*", SequenceSet.new("1:4").append(5..).string
assert_equal "5:*,1:4", SequenceSet.new("5:*").append(1..4).string
# also works from empty
assert_equal "5,1", SequenceSet.new.append(5).append(1).string
# also works when *previously* input was non-strings
assert_equal "*,1", SequenceSet.new(:*).append(1).string
assert_equal "1,5", SequenceSet.new(1).append("5").string
assert_equal "1:6,4:9", SequenceSet.new(1..6).append(4..9).string
assert_equal "1:4,5:*", SequenceSet.new(1..4).append(5..).string
assert_equal "5:*,1:4", SequenceSet.new(5..).append(1..4).string
end

test "#merge" do
Expand Down

0 comments on commit 4c9b1a2

Please sign in to comment.