Skip to content

Commit 6479e0b

Browse files
committed
* lib/net/ftp.rb (gets, readline): read lines without LF properly.
[ruby-core:63205] [Bug ruby#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
1 parent d689dca commit 6479e0b

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Tue Jun 17 16:41:49 2014 Shugo Maeda <shugo@ruby-lang.org>
2+
3+
* lib/net/ftp.rb (gets, readline): read lines without LF properly.
4+
[ruby-core:63205] [Bug #9949]
5+
6+
* test/net/ftp/test_buffered_socket.rb: related test.
7+
18
Tue Jun 17 12:35:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
29

310
* eval.c (extract_raise_opts): pass unknown options to the

lib/net/ftp.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,13 +1105,16 @@ def read(len = nil)
11051105
end
11061106

11071107
def gets
1108-
return readuntil("\n")
1109-
rescue EOFError
1110-
return nil
1108+
line = readuntil("\n", true)
1109+
return line.empty? ? nil : line
11111110
end
11121111

11131112
def readline
1114-
return readuntil("\n")
1113+
line = gets
1114+
if line.nil?
1115+
raise EOFError, "end of file reached"
1116+
end
1117+
return line
11151118
end
11161119
end
11171120
# :startdoc:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require "net/ftp"
2+
require "test/unit"
3+
require "ostruct"
4+
require "stringio"
5+
6+
class FTPTest < Test::Unit::TestCase
7+
def test_gets_empty
8+
sock = create_buffered_socket("")
9+
assert_equal(nil, sock.gets)
10+
end
11+
12+
def test_gets_one_line
13+
sock = create_buffered_socket("foo\n")
14+
assert_equal("foo\n", sock.gets)
15+
end
16+
17+
def test_gets_one_line_without_term
18+
sock = create_buffered_socket("foo")
19+
assert_equal("foo", sock.gets)
20+
end
21+
22+
def test_gets_two_lines
23+
sock = create_buffered_socket("foo\nbar\n")
24+
assert_equal("foo\n", sock.gets)
25+
assert_equal("bar\n", sock.gets)
26+
end
27+
28+
def test_gets_two_lines_without_term
29+
sock = create_buffered_socket("foo\nbar")
30+
assert_equal("foo\n", sock.gets)
31+
assert_equal("bar", sock.gets)
32+
end
33+
34+
private
35+
36+
def create_buffered_socket(s)
37+
io = StringIO.new(s)
38+
return Net::FTP::BufferedSocket.new(io)
39+
end
40+
end

0 commit comments

Comments
 (0)