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

ruby-changes:23107

From: nobu <ko1@a...>
Date: Wed, 28 Mar 2012 15:06:30 +0900 (JST)
Subject: [ruby-changes:23107] nobu:r35157 (trunk): * marshal.c (r_symreal): default to ASCII-8BIT for non-ascii symbols,

nobu	2012-03-28 15:06:20 +0900 (Wed, 28 Mar 2012)

  New Revision: 35157

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

  Log:
    * marshal.c (r_symreal): default to ASCII-8BIT for non-ascii symbols,
      otherwise it should be converted to US-ASCII in rb_intern_str() if
      possible.  [ruby-core:43762][Bug #6209]

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35156)
+++ ChangeLog	(revision 35157)
@@ -1,3 +1,9 @@
+Wed Mar 28 15:06:18 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (r_symreal): default to ASCII-8BIT for non-ascii symbols,
+	  otherwise it should be converted to US-ASCII in rb_intern_str() if
+	  possible.  [ruby-core:43762][Bug #6209]
+
 Wed Mar 28 08:44:24 2012  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych.rb: updating version to match gem
Index: marshal.c
===================================================================
--- marshal.c	(revision 35156)
+++ marshal.c	(revision 35157)
@@ -1161,8 +1161,7 @@
 	    idx = id2encidx(id, r_object(arg));
 	}
     }
-    if (idx < 0) idx = rb_usascii_encindex();
-    rb_enc_associate_index(s, idx);
+    if (idx > 0) rb_enc_associate_index(s, idx);
     id = rb_intern_str(s);
     st_insert(arg->symbols, (st_data_t)n, (st_data_t)id);
 
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 35156)
+++ test/ruby/test_marshal.rb	(revision 35157)
@@ -455,6 +455,15 @@
     assert_equal(o1, o2)
   end
 
+  def test_marshal_symbol_ascii8bit
+    bug6209 = '[ruby-core:43762]'
+    o1 = "\xff".force_encoding("ASCII-8BIT").intern
+    m = Marshal.dump(o1)
+    o2 = nil
+    assert_nothing_raised(EncodingError, bug6209) {o2 = Marshal.load(m)}
+    assert_equal(o1, o2, bug6209)
+  end
+
   class PrivateClass
     def initialize(foo)
       @foo = foo

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

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