Skip to content

Commit ab4f80e

Browse files
committed
💥 Validate Set inputs to SequenceSet
Each member of the set should be an integer, a range, or a sequence-set formatted string. SequenceSet should not allow Set inputs to be nested.
1 parent 523ec01 commit ab4f80e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/net/imap/sequence_set.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class IMAP
3737
#
3838
# SequenceSet.new may receive a single optional argument: a non-zero 32 bit
3939
# unsigned integer, a range, a <tt>sequence-set</tt> formatted string,
40-
# another sequence set, or an enumerable containing any of these.
40+
# another sequence set, a Set (containing only numbers), or an enumerable
41+
# containing any of these (which may be nested).
4142
#
4243
# set = Net::IMAP::SequenceSet.new(1)
4344
# set.valid_string #=> "1"
@@ -1271,6 +1272,7 @@ def input_to_tuples(obj)
12711272
when *STARS, Integer, Range then [input_to_tuple(obj)]
12721273
when String then str_to_tuples obj
12731274
when SequenceSet then obj.tuples
1275+
when Set then obj.map { to_tuple_int _1 }
12741276
when ENUMABLE then obj.flat_map { input_to_tuples _1 }
12751277
when nil then []
12761278
else

test/net/imap/test_sequence_set.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def compare_to_reference_set(nums, set, seqset)
9999
assert_raise DataFormatError do SequenceSet.new "2 " end
100100
assert_raise DataFormatError do SequenceSet.new "2," end
101101
assert_raise DataFormatError do SequenceSet.new Time.now end
102+
assert_raise DataFormatError do SequenceSet.new Set[1, [2]] end
103+
assert_raise DataFormatError do SequenceSet.new Set[1..20] end
102104
end
103105

104106
test ".new, input may be empty" do

0 commit comments

Comments
 (0)