stringio.c: encoding at EOF
* ext/stringio/stringio.c (strio_read): should return string with the external encoding, at EOF too. [ruby-core:82349] [Bug #13806] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
201d0e7e33
commit
6ee82564fa
@ -1392,12 +1392,14 @@ strio_read(int argc, VALUE *argv, VALUE self)
|
|||||||
case 0:
|
case 0:
|
||||||
len = RSTRING_LEN(ptr->string);
|
len = RSTRING_LEN(ptr->string);
|
||||||
if (len <= ptr->pos) {
|
if (len <= ptr->pos) {
|
||||||
|
rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr);
|
||||||
if (NIL_P(str)) {
|
if (NIL_P(str)) {
|
||||||
str = rb_str_new(0, 0);
|
str = rb_str_new(0, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_str_resize(str, 0);
|
rb_str_resize(str, 0);
|
||||||
}
|
}
|
||||||
|
rb_enc_associate(str, enc);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -577,6 +577,13 @@ class TestStringIO < Test::Unit::TestCase
|
|||||||
s = "0123456789"
|
s = "0123456789"
|
||||||
assert_same(s, f.read(nil, s))
|
assert_same(s, f.read(nil, s))
|
||||||
assert_equal("\u3042\u3044", s)
|
assert_equal("\u3042\u3044", s)
|
||||||
|
|
||||||
|
bug13806 = '[ruby-core:82349] [Bug #13806]'
|
||||||
|
assert_string("", Encoding::UTF_8, f.read, bug13806)
|
||||||
|
assert_string("", Encoding::UTF_8, f.read(nil, nil), bug13806)
|
||||||
|
s.force_encoding(Encoding::US_ASCII)
|
||||||
|
assert_same(s, f.read(nil, s))
|
||||||
|
assert_string("", Encoding::UTF_8, s, bug13806)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_readpartial
|
def test_readpartial
|
||||||
@ -756,4 +763,8 @@ class TestStringIO < Test::Unit::TestCase
|
|||||||
assert_equal(0x100000, s.pos)
|
assert_equal(0x100000, s.pos)
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_string(content, encoding, str, mesg = nil)
|
||||||
|
assert_equal([content, encoding], [str, str.encoding], mesg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user