1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

net/imap: Fix ArgumentError in send_string_data

Thanks to ShockwaveNN (Pavel Lobashov) for reporting the bug.
[ruby-core:86990] [Bug #14750]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2018-05-11 12:39:23 +00:00
parent b787be4e45
commit 59630683d6
2 changed files with 44 additions and 7 deletions

View file

@ -1325,11 +1325,11 @@ module Net
when nil
put_string("NIL")
when String
send_string_data(data)
send_string_data(data, tag)
when Integer
send_number_data(data)
when Array
send_list_data(data)
send_list_data(data, tag)
when Time
send_time_data(data)
when Symbol
@ -1339,13 +1339,13 @@ module Net
end
end
def send_string_data(str)
def send_string_data(str, tag = nil)
case str
when ""
put_string('""')
when /[\x80-\xff\r\n]/n
# literal
send_literal(str)
send_literal(str, tag)
when /[(){ \x00-\x1f\x7f%*"\\]/n
# quoted string
send_quoted_string(str)
@ -1358,7 +1358,7 @@ module Net
put_string('"' + str.gsub(/["\\]/n, "\\\\\\&") + '"')
end
def send_literal(str, tag)
def send_literal(str, tag = nil)
synchronize do
put_string("{" + str.bytesize.to_s + "}" + CRLF)
@continued_command_tag = tag
@ -1379,7 +1379,7 @@ module Net
put_string(num.to_s)
end
def send_list_data(list)
def send_list_data(list, tag = nil)
put_string("(")
first = true
list.each do |i|
@ -1388,7 +1388,7 @@ module Net
else
put_string(" ")
end
send_data(i)
send_data(i, tag)
end
put_string(")")
end

View file

@ -530,6 +530,43 @@ class IMAPTest < Test::Unit::TestCase
end
end
def test_send_literal
server = create_tcp_server
port = server.addr[1]
requests = []
literal = nil
@threads << Thread.start do
sock = server.accept
begin
sock.print("* OK test server\r\n")
line = sock.gets
requests.push(line)
size = line.slice(/{(\d+)}\r\n/, 1).to_i
sock.print("+ Ready for literal data\r\n")
literal = sock.read(size)
requests.push(sock.gets)
sock.print("RUBY0001 OK TEST completed\r\n")
sock.gets
sock.print("* BYE terminating connection\r\n")
sock.print("RUBY0002 OK LOGOUT completed\r\n")
ensure
sock.close
server.close
end
end
begin
imap = Net::IMAP.new(server_addr, :port => port)
imap.send(:send_command, "TEST", ["\xDE\xAD\xBE\xEF".b])
assert_equal(2, requests.length)
assert_equal("RUBY0001 TEST ({4}\r\n", requests[0])
assert_equal("\xDE\xAD\xBE\xEF".b, literal)
assert_equal(")\r\n", requests[1])
imap.logout
ensure
imap.disconnect
end
end
def test_disconnect
server = create_tcp_server
port = server.addr[1]