ruby-changes:34537
From: nagachika <ko1@a...>
Date: Mon, 30 Jun 2014 03:08:54 +0900 (JST)
Subject: [ruby-changes:34537] nagachika:r46618 (ruby_2_1): merge revision(s) r46457, r46458: [Backport #9949]
nagachika 2014-06-30 03:08:43 +0900 (Mon, 30 Jun 2014) New Revision: 46618 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46618 Log: merge revision(s) r46457,r46458: [Backport #9949] * lib/net/ftp.rb (gets, readline): read lines without LF properly. [ruby-core:63205] [Bug #9949] * test/net/ftp/test_buffered_socket.rb: related test. Added files: branches/ruby_2_1/test/net/ftp/test_buffered_socket.rb Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/lib/net/ftp.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 46617) +++ ruby_2_1/ChangeLog (revision 46618) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Mon Jun 30 03:07:22 2014 Shugo Maeda <shugo@r...> + + * lib/net/ftp.rb (gets, readline): read lines without LF properly. + [ruby-core:63205] [Bug #9949] + + * test/net/ftp/test_buffered_socket.rb: related test. + Mon Jun 30 02:59:08 2014 Shugo Maeda <shugo@r...> * lib/net/imap.rb (body_type_1part): Gmail IMAP reports a body Index: ruby_2_1/lib/net/ftp.rb =================================================================== --- ruby_2_1/lib/net/ftp.rb (revision 46617) +++ ruby_2_1/lib/net/ftp.rb (revision 46618) @@ -1105,13 +1105,16 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_1/lib/net/ftp.rb#L1105 end def gets - return readuntil("\n") - rescue EOFError - return nil + line = readuntil("\n", true) + return line.empty? ? nil : line end def readline - return readuntil("\n") + line = gets + if line.nil? + raise EOFError, "end of file reached" + end + return line end end # :startdoc: Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 46617) +++ ruby_2_1/version.h (revision 46618) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-06-30" -#define RUBY_PATCHLEVEL 155 +#define RUBY_PATCHLEVEL 156 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_1/test/net/ftp/test_buffered_socket.rb =================================================================== --- ruby_2_1/test/net/ftp/test_buffered_socket.rb (revision 0) +++ ruby_2_1/test/net/ftp/test_buffered_socket.rb (revision 46618) @@ -0,0 +1,40 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/net/ftp/test_buffered_socket.rb#L1 +require "net/ftp" +require "test/unit" +require "ostruct" +require "stringio" + +class FTPTest < Test::Unit::TestCase + def test_gets_empty + sock = create_buffered_socket("") + assert_equal(nil, sock.gets) + end + + def test_gets_one_line + sock = create_buffered_socket("foo\n") + assert_equal("foo\n", sock.gets) + end + + def test_gets_one_line_without_term + sock = create_buffered_socket("foo") + assert_equal("foo", sock.gets) + end + + def test_gets_two_lines + sock = create_buffered_socket("foo\nbar\n") + assert_equal("foo\n", sock.gets) + assert_equal("bar\n", sock.gets) + end + + def test_gets_two_lines_without_term + sock = create_buffered_socket("foo\nbar") + assert_equal("foo\n", sock.gets) + assert_equal("bar", sock.gets) + end + + private + + def create_buffered_socket(s) + io = StringIO.new(s) + return Net::FTP::BufferedSocket.new(io) + end +end Property changes on: ruby_2_1/test/net/ftp/test_buffered_socket.rb ___________________________________________________________________ Added: svn:eol-style + LF Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r46457-46458 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/