ruby-changes:62328
From: Nobuyoshi <ko1@a...>
Date: Mon, 20 Jul 2020 14:59:42 +0900 (JST)
Subject: [ruby-changes:62328] ddb2acbba6 (master): [ruby/stringio] No compatibility check in US-ASCII case
https://git.ruby-lang.org/ruby.git/commit/?id=ddb2acbba6 From ddb2acbba60302201f01175f019d8ecd99934add Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 19 Jul 2020 16:08:03 +0900 Subject: [ruby/stringio] No compatibility check in US-ASCII case https://github.com/ruby/stringio/commit/59df1c8293 diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 9ab8537..d55af51 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1429,14 +1429,15 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1429 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; diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index ab448f0..54f5716 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -195,9 +195,15 @@ class TestStringIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L195 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, -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/