ruby-changes:35907
From: usa <ko1@a...>
Date: Fri, 17 Oct 2014 13:20:52 +0900 (JST)
Subject: [ruby-changes:35907] usa:r47988 (ruby_2_0_0): merge revision(s) 47716: [Backport #10285]
usa 2014-10-17 13:20:40 +0900 (Fri, 17 Oct 2014) New Revision: 47988 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47988 Log: merge revision(s) 47716: [Backport #10285] * ext/stringio/stringio.c (strio_write): ASCII-8BIT StringIO should be writable any encoding strings, without conversion. [ruby-core:65240] [Bug #10285] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/ext/stringio/stringio.c branches/ruby_2_0_0/test/stringio/test_stringio.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 47987) +++ ruby_2_0_0/ChangeLog (revision 47988) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Fri Oct 17 13:19:44 2014 Nobuyoshi Nakada <nobu@r...> + + * ext/stringio/stringio.c (strio_write): ASCII-8BIT StringIO + should be writable any encoding strings, without conversion. + [ruby-core:65240] [Bug #10285] + Fri Oct 17 13:10:08 2014 Nobuyoshi Nakada <nobu@r...> * vm_eval.c (eval_string_with_cref): fix super from eval with Index: ruby_2_0_0/ext/stringio/stringio.c =================================================================== --- ruby_2_0_0/ext/stringio/stringio.c (revision 47987) +++ ruby_2_0_0/ext/stringio/stringio.c (revision 47988) @@ -1171,12 +1171,13 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/stringio/stringio.c#L1171 struct StringIO *ptr = writable(self); long len, olen; rb_encoding *enc, *enc2; + rb_encoding *const ascii8bit = rb_ascii8bit_encoding(); if (!RB_TYPE_P(str, T_STRING)) str = rb_obj_as_string(str); enc = rb_enc_get(ptr->string); enc2 = rb_enc_get(str); - if (enc != enc2 && enc != rb_ascii8bit_encoding()) { + if (enc != enc2 && enc != ascii8bit) { str = rb_str_conv_enc(str, enc2, enc); } len = RSTRING_LEN(str); @@ -1187,7 +1188,7 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/stringio/stringio.c#L1188 ptr->pos = olen; } if (ptr->pos == olen) { - if (enc2 == rb_ascii8bit_encoding()) { + if (enc == ascii8bit || enc2 == ascii8bit) { rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc); OBJ_INFECT(ptr->string, str); } Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 47987) +++ ruby_2_0_0/version.h (revision 47988) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-10-17" -#define RUBY_PATCHLEVEL 588 +#define RUBY_PATCHLEVEL 589 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 10 Index: ruby_2_0_0/test/stringio/test_stringio.rb =================================================================== --- ruby_2_0_0/test/stringio/test_stringio.rb (revision 47987) +++ ruby_2_0_0/test/stringio/test_stringio.rb (revision 47988) @@ -129,6 +129,18 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/stringio/test_stringio.rb#L129 assert_equal(Encoding::UTF_8, s.encoding, "honor the original encoding over ASCII-8BIT") end + def test_set_encoding + bug10285 = '[ruby-core:65240] [Bug #10285]' + f = StringIO.new() + f.set_encoding(Encoding::ASCII_8BIT) + f.write("quz \x83 mat".b) + s = "foo \x97 bar".force_encoding(Encoding::WINDOWS_1252) + assert_nothing_raised(Encoding::CompatibilityError, bug10285) { + f.write(s) + } + assert_equal(Encoding::ASCII_8BIT, f.string.encoding, bug10285) + end + def test_mode_error f = StringIO.new("", "r") assert_raise(IOError) { f.write("foo") } Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r47716 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/