summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 22:08:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 22:08:45 +0000
commitbfcd4e54538b1dd415ed1f3bebe482df11b383c2 (patch)
treecd7525102def020f688ca4bbd27bf74814fc95d9
parent15dad95dfcb092fea28ebc1e1a6aba6df119b1e0 (diff)
* ext/stringio/stringio.c (strio_getline): round upto next char
boundary. [ruby-dev:42674] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/stringio/stringio.c2
-rw-r--r--test/stringio/test_stringio.rb6
3 files changed, 12 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index fb1e352..7c03961 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Dec 3 07:08:42 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/stringio/stringio.c (strio_getline): round upto next char
+ boundary. [ruby-dev:42674]
+
Fri Dec 3 06:52:46 2010 Tanaka Akira <akr@fsij.org>
* compile.c: parenthesize macro arguments.
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 75f8cd7..7edf711 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -954,7 +954,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
e = s + RSTRING_LEN(ptr->string);
s += ptr->pos;
if (limit > 0 && s + limit < e) {
- e = s + limit;
+ e = rb_enc_right_char_head(s, s + limit, e, rb_enc_get(ptr->string));
}
if (NIL_P(str)) {
str = strio_substr(ptr, ptr->pos, e - s);
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 30284fa..b7327ad 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -378,6 +378,12 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("a" * 10000 + "zz", f.gets("zz"))
f = StringIO.new("a" * 10000 + "zz!")
assert_equal("a" * 10000 + "zz!", f.gets("zzz"))
+
+ bug4112 = '[ruby-dev:42674]'
+ ["a".encode("utf-16be"), "\u3042"].each do |s|
+ assert_equal(s, StringIO.new(s).gets(1), bug4112)
+ assert_equal(s, StringIO.new(s).gets(nil, 1), bug4112)
+ end
end
def test_each