diff options
| author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-21 06:33:05 +0000 |
|---|---|---|
| committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-21 06:33:05 +0000 |
| commit | f9df459a31bef331ed0610b859effde63ea9a674 (patch) | |
| tree | ef1aea83ff6dff2ee9a3f473d6403364d9c377c2 | |
| parent | ac714c2d300eeb58ef1e19bbef1af4bedaec89d2 (diff) | |
* ext/stringio/stringio.c (strio_getline): fix for "" as separator.
[ruby-dev:34591] (Backport r17739 by Yusuke Endoh from trunk).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | ext/stringio/stringio.c | 2 | ||||
| -rw-r--r-- | test/stringio/test_stringio.rb | 12 |
3 files changed, 18 insertions, 1 deletions
@@ -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) |
