summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/stringio/stringio.c2
-rw-r--r--test/stringio/test_stringio.rb12
3 files changed, 18 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 940ae97a12..64dfdcd8a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Dec 21 15:27:48 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+
+ * ext/stringio/stringio.c (strio_getline): fix for "" as separator.
+ [ruby-dev:34591] (Backport r17739 by Yusuke Endoh from trunk).
+
Mon Dec 21 15:20:42 2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/openssl/{common.pem,max.pem}: added fixture certificates.
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 16a836454f..c38c92eb82 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -935,7 +935,7 @@ strio_getline(argc, argv, ptr)
s = p;
while ((p = memchr(p, '\n', e - p)) && (p != e)) {
if (*++p == '\n') {
- e = p;
+ e = p + 1;
break;
}
}
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 8e52065dd4..c02717f431 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -56,6 +56,18 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("abc\n\n", StringIO.new("abc\n\ndef\n").gets(""))
end
+ def test_gets_paragraph
+ assert_equal("abc\n\n", StringIO.new("abc\n\ndef\n").gets(""))
+ assert_equal("abc\n\n", StringIO.new("\nabc\n\ndef\n").gets(""))
+ assert_equal("abc", StringIO.new("abc").gets(""))
+ assert_equal("abc\n", StringIO.new("abc\n").gets(""))
+ assert_equal(nil, StringIO.new("").gets(""))
+ assert_equal("def\n", StringIO.new("\n\ndef\n").gets(""))
+ s = StringIO.new("\n\nabc\n\n\n\ndef\n")
+ assert_equal("abc\n\n", s.gets(""))
+ assert_equal("def\n", s.gets(""))
+ end
+
def test_readlines
assert_equal([], StringIO.new("").readlines)
assert_equal(["\n"], StringIO.new("\n").readlines)