Skip to content

Commit

Permalink
🥅 Raise ArgumentError on multiple search charset args
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Dec 15, 2024
1 parent 3bdd1f9 commit 8285049
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3151,6 +3151,10 @@ def enforce_logindisabled?
end

def search_args(keys, charset = nil)
# NOTE: not handling combined RETURN and CHARSET for raw strings
if charset && keys in /\ACHARSET\b/i | Array[/\ACHARSET\z/i, *]
raise ArgumentError, "multiple charset arguments"
end
args = normalize_searching_criteria(keys)
args.prepend("CHARSET", charset) if charset
args
Expand Down
18 changes: 18 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,24 @@ def seqset_coercible.to_sequence_set
end
end

test("#search/#uid_search with invalid arguments") do
with_fake_server do |server, imap|
server.on "SEARCH" do |cmd| cmd.fail_no "should fail before this" end
server.on "UID SEARCH" do |cmd| cmd.fail_no "should fail before this" end

assert_raise(ArgumentError) do
imap.search(["charset", "foo", "ALL"], "bar")
end
assert_raise(ArgumentError) do
imap.search("charset foo ALL", "bar")
end
# Parsing return opts is too complicated, for now.
# assert_raise(ArgumentError) do
# imap.search("return () charset foo ALL", "bar")
# end
end
end

test("missing server SEARCH response") do
with_fake_server do |server, imap|
server.on "SEARCH", &:done_ok
Expand Down

0 comments on commit 8285049

Please sign in to comment.