summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/stringio/stringio.c3
-rw-r--r--test/stringio/test_stringio.rb2
2 files changed, 4 insertions, 1 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 032f80a..26dc1a0 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -1149,7 +1149,8 @@ strio_gets(int argc, VALUE *argv, VALUE self)
VALUE str;
if (prepare_getline_args(&arg, argc, argv)->limit == 0) {
- return rb_str_new(0, 0);
+ struct StringIO *ptr = readable(self);
+ return rb_enc_str_new(0, 0, get_enc(ptr));
}
str = strio_getline(&arg, readable(self));
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 89fc54e..8faf4d8 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -79,6 +79,8 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("def\n", stringio.gets(""))
assert_raise(TypeError){StringIO.new("").gets(1, 1)}
assert_nothing_raised {StringIO.new("").gets(nil, nil)}
+
+ assert_string("", Encoding::UTF_8, StringIO.new("foo").gets(0))
end
def test_gets_chomp