[ruby/stringio] No compatibility check in US-ASCII case
https://github.com/ruby/stringio/commit/59df1c8293
This commit is contained in:
parent
c62aff1632
commit
ddb2acbba6
Notes:
git
2020-07-20 14:59:45 +09:00
@ -1429,14 +1429,15 @@ strio_write(VALUE self, VALUE str)
|
||||
long len, olen;
|
||||
rb_encoding *enc, *enc2;
|
||||
rb_encoding *const ascii8bit = rb_ascii8bit_encoding();
|
||||
rb_encoding *usascii = 0;
|
||||
|
||||
if (!RB_TYPE_P(str, T_STRING))
|
||||
str = rb_obj_as_string(str);
|
||||
enc = get_enc(ptr);
|
||||
enc2 = rb_enc_get(str);
|
||||
if (enc != enc2 && enc != ascii8bit) {
|
||||
if (enc != enc2 && enc != ascii8bit && enc != (usascii = rb_usascii_encoding())) {
|
||||
VALUE converted = rb_str_conv_enc(str, enc2, enc);
|
||||
if (converted == str && enc2 != ascii8bit) { /* conversion failed */
|
||||
if (converted == str && enc2 != ascii8bit && enc2 != usascii) { /* conversion failed */
|
||||
rb_enc_check(rb_enc_from_encoding(enc), str);
|
||||
}
|
||||
str = converted;
|
||||
|
@ -195,9 +195,15 @@ class TestStringIO < Test::Unit::TestCase
|
||||
s = StringIO.new.set_encoding(conversion_encoding)
|
||||
s.write(convertible)
|
||||
assert_equal(conversion_encoding, s.string.encoding)
|
||||
|
||||
s = StringIO.new.set_encoding(Encoding::UTF_8)
|
||||
s.write("foo".force_encoding("ISO-8859-1"), convertible)
|
||||
assert_equal(Encoding::UTF_8, s.string.encoding)
|
||||
|
||||
s = StringIO.new.set_encoding(Encoding::US_ASCII)
|
||||
s.write("foo".force_encoding("US-ASCII"), convertible)
|
||||
assert_equal(Encoding::UTF_8, s.string.encoding)
|
||||
|
||||
all_assertions do |a|
|
||||
[
|
||||
inconvertible,
|
||||
|
Loading…
x
Reference in New Issue
Block a user