diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-07 03:17:25 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-07 03:17:25 +0000 |
commit | ea0bf82630a1aa8ad6c56b9d50c297ba1aab6fb5 (patch) | |
tree | 0f59cbd0eeffd43bfe5a3b88db25f0fe8004c52b | |
parent | 5ff287ad67935ac4646beafaf8d9e31884917345 (diff) |
merge revision(s) 46457,46458: [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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@46735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/net/ftp.rb | 11 | ||||
-rw-r--r-- | test/net/ftp/test_buffered_socket.rb | 40 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 55 insertions, 5 deletions
@@ -1,3 +1,10 @@ +Mon Jul 7 12:16:54 2014 Shugo Maeda <shugo@ruby-lang.org> + + * 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 Jul 7 12:13:09 2014 Shugo Maeda <shugo@ruby-lang.org> * lib/net/imap.rb (body_type_1part): Gmail IMAP reports a body diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index c2cf5f3af4..20b8faa134 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -1102,13 +1102,16 @@ module Net 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: diff --git a/test/net/ftp/test_buffered_socket.rb b/test/net/ftp/test_buffered_socket.rb new file mode 100644 index 0000000000..f9eefcd988 --- /dev/null +++ b/test/net/ftp/test_buffered_socket.rb @@ -0,0 +1,40 @@ +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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-07-07" -#define RUBY_PATCHLEVEL 519 +#define RUBY_PATCHLEVEL 520 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 7 |