1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/stringio] Accept external and internal encodings pair

Fix https://github.com/ruby/stringio/pull/16

https://github.com/ruby/stringio/commit/c8a69e80d2
This commit is contained in:
Nobuyoshi Nakada 2022-05-30 13:46:31 +09:00 committed by git
parent 4cc880e994
commit d3e986d9ab
2 changed files with 14 additions and 1 deletions

View file

@ -1719,7 +1719,14 @@ strio_set_encoding(int argc, VALUE *argv, VALUE self)
enc = rb_default_external_encoding();
}
else {
enc = rb_to_encoding(ext_enc);
enc = rb_find_encoding(ext_enc);
if (!enc) {
struct rb_io_enc_t convconfig;
int oflags, fmode;
VALUE vmode = rb_str_append(rb_str_new_cstr("r:"), ext_enc);
rb_io_extract_modeenc(&vmode, 0, Qnil, &oflags, &fmode, &convconfig);
enc = convconfig.enc2;
}
}
ptr->enc = enc;
if (WRITABLE(self)) {

View file

@ -256,6 +256,12 @@ class TestStringIO < Test::Unit::TestCase
f.set_encoding(Encoding::ASCII_8BIT)
}
assert_equal("foo\x83".b, f.gets)
f = StringIO.new()
f.set_encoding("ISO-8859-16:ISO-8859-1")
assert_equal(Encoding::ISO_8859_16, f.external_encoding)
assert_equal(Encoding::ISO_8859_16, f.string.encoding)
assert_nil(f.internal_encoding)
end
def test_mode_error