зеркало из https://github.com/github/ruby.git
* 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/trunk@46457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d689dca633
Коммит
6479e0b04f
|
@ -1,3 +1,10 @@
|
||||||
|
Tue Jun 17 16:41:49 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.
|
||||||
|
|
||||||
Tue Jun 17 12:35:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Jun 17 12:35:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (extract_raise_opts): pass unknown options to the
|
* eval.c (extract_raise_opts): pass unknown options to the
|
||||||
|
|
|
@ -1105,13 +1105,16 @@ module Net
|
||||||
end
|
end
|
||||||
|
|
||||||
def gets
|
def gets
|
||||||
return readuntil("\n")
|
line = readuntil("\n", true)
|
||||||
rescue EOFError
|
return line.empty? ? nil : line
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def readline
|
def readline
|
||||||
return readuntil("\n")
|
line = gets
|
||||||
|
if line.nil?
|
||||||
|
raise EOFError, "end of file reached"
|
||||||
|
end
|
||||||
|
return line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче