ruby-changes:52212
From: nagachika <ko1@a...>
Date: Sat, 18 Aug 2018 01:21:02 +0900 (JST)
Subject: [ruby-changes:52212] nagachika:r64420 (ruby_2_5): merge revision(s) 63396: [Backport #14750]
nagachika 2018-08-18 01:20:53 +0900 (Sat, 18 Aug 2018) New Revision: 64420 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64420 Log: merge revision(s) 63396: [Backport #14750] net/imap: Fix ArgumentError in send_string_data Thanks to ShockwaveNN (Pavel Lobashov) for reporting the bug. [ruby-core:86990] [Bug #14750] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/lib/net/imap.rb branches/ruby_2_5/test/net/imap/test_imap.rb branches/ruby_2_5/version.h Index: ruby_2_5/lib/net/imap.rb =================================================================== --- ruby_2_5/lib/net/imap.rb (revision 64419) +++ ruby_2_5/lib/net/imap.rb (revision 64420) @@ -1323,11 +1323,11 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/net/imap.rb#L1323 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 @@ -1337,13 +1337,13 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/net/imap.rb#L1337 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) @@ -1356,7 +1356,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/net/imap.rb#L1356 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 @@ -1377,7 +1377,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/net/imap.rb#L1377 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| @@ -1386,7 +1386,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/net/imap.rb#L1386 else put_string(" ") end - send_data(i) + send_data(i, tag) end put_string(")") end Index: ruby_2_5/test/net/imap/test_imap.rb =================================================================== --- ruby_2_5/test/net/imap/test_imap.rb (revision 64419) +++ ruby_2_5/test/net/imap/test_imap.rb (revision 64420) @@ -530,6 +530,43 @@ class IMAPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/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] Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 64419) +++ ruby_2_5/version.h (revision 64420) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.2" #define RUBY_RELEASE_DATE "2018-08-18" -#define RUBY_PATCHLEVEL 70 +#define RUBY_PATCHLEVEL 71 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 8 Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 64419) +++ ruby_2_5 (revision 64420) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r63396 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/