ruby-changes:51189
From: shugo <ko1@a...>
Date: Fri, 11 May 2018 21:39:31 +0900 (JST)
Subject: [ruby-changes:51189] shugo:r63396 (trunk): net/imap: Fix ArgumentError in send_string_data
shugo 2018-05-11 21:39:23 +0900 (Fri, 11 May 2018) New Revision: 63396 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63396 Log: net/imap: Fix ArgumentError in send_string_data Thanks to ShockwaveNN (Pavel Lobashov) for reporting the bug. [ruby-core:86990] [Bug #14750] Modified files: trunk/lib/net/imap.rb trunk/test/net/imap/test_imap.rb Index: lib/net/imap.rb =================================================================== --- lib/net/imap.rb (revision 63395) +++ lib/net/imap.rb (revision 63396) @@ -1325,11 +1325,11 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1325 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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1339 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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1358 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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1379 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 https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1388 else put_string(" ") end - send_data(i) + send_data(i, tag) end put_string(")") end Index: test/net/imap/test_imap.rb =================================================================== --- test/net/imap/test_imap.rb (revision 63395) +++ test/net/imap/test_imap.rb (revision 63396) @@ -530,6 +530,43 @@ class IMAPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/imap/test_imap.rb#L530 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] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/