[前][次][番号順一覧][スレッド一覧]

ruby-changes:35901

From: nagachika <ko1@a...>
Date: Thu, 16 Oct 2014 22:19:17 +0900 (JST)
Subject: [ruby-changes:35901] nagachika:r47982 (ruby_2_1): merge revision(s) r47716: [Backport #10285]

nagachika	2014-10-16 22:19:07 +0900 (Thu, 16 Oct 2014)

  New Revision: 47982

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47982

  Log:
    merge revision(s) r47716: [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_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/ext/stringio/stringio.c
    branches/ruby_2_1/test/stringio/test_stringio.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 47981)
+++ ruby_2_1/ChangeLog	(revision 47982)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Thu Oct 16 22:10:11 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]
+
 Thu Oct 16 22:06:03 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_eval.c (eval_string_with_cref): fix super from eval with
Index: ruby_2_1/ext/stringio/stringio.c
===================================================================
--- ruby_2_1/ext/stringio/stringio.c	(revision 47981)
+++ ruby_2_1/ext/stringio/stringio.c	(revision 47982)
@@ -1169,12 +1169,13 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/stringio/stringio.c#L1169
     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);
@@ -1185,7 +1186,7 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/stringio/stringio.c#L1186
 	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_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47981)
+++ ruby_2_1/version.h	(revision 47982)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.4"
 #define RUBY_RELEASE_DATE "2014-10-16"
-#define RUBY_PATCHLEVEL 258
+#define RUBY_PATCHLEVEL 259
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 10
Index: ruby_2_1/test/stringio/test_stringio.rb
===================================================================
--- ruby_2_1/test/stringio/test_stringio.rb	(revision 47981)
+++ ruby_2_1/test/stringio/test_stringio.rb	(revision 47982)
@@ -137,6 +137,18 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/stringio/test_stringio.rb#L137
     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_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r47716


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]