ruby-changes:34376
From: shugo <ko1@a...>
Date: Tue, 17 Jun 2014 16:45:05 +0900 (JST)
Subject: [ruby-changes:34376] shugo:r46457 (trunk): * lib/net/ftp.rb (gets, readline): read lines without LF properly.
shugo 2014-06-17 16:44:53 +0900 (Tue, 17 Jun 2014) New Revision: 46457 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46457 Log: * 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: trunk/test/net/ftp/test_buffered_socket.rb Modified files: trunk/ChangeLog trunk/lib/net/ftp.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46456) +++ ChangeLog (revision 46457) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jun 17 16:41:49 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. + Tue Jun 17 12:35:24 2014 Nobuyoshi Nakada <nobu@r...> * eval.c (extract_raise_opts): pass unknown options to the Index: lib/net/ftp.rb =================================================================== --- lib/net/ftp.rb (revision 46456) +++ lib/net/ftp.rb (revision 46457) @@ -1105,13 +1105,16 @@ module Net https://github.com/ruby/ruby/blob/trunk/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: test/net/ftp/test_buffered_socket.rb =================================================================== --- test/net/ftp/test_buffered_socket.rb (revision 0) +++ test/net/ftp/test_buffered_socket.rb (revision 46457) @@ -0,0 +1,40 @@ https://github.com/ruby/ruby/blob/trunk/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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/