aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 fb1e352224..7c039617f9 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 75f8cd7f6d..7edf7119e3 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 30284faee2..b7327adced 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