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

ruby-changes:38252

From: nobu <ko1@a...>
Date: Thu, 16 Apr 2015 23:29:00 +0900 (JST)
Subject: [ruby-changes:38252] nobu:r50333 (trunk): marshal.c: class name encoding

nobu	2015-04-16 23:28:29 +0900 (Thu, 16 Apr 2015)

  New Revision: 50333

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

  Log:
    marshal.c: class name encoding
    
    * marshal.c (r_object0): preserve the encoding of the class name
      in an error message, in the case of USRMARSHAL without
      marshal_load method.

  Modified files:
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb
Index: marshal.c
===================================================================
--- marshal.c	(revision 50332)
+++ marshal.c	(revision 50333)
@@ -1837,7 +1837,8 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1837
 
       case TYPE_USRMARSHAL:
         {
-	    VALUE klass = path2class(r_unique(arg));
+	    VALUE name = r_unique(arg);
+	    VALUE klass = path2class(name);
 	    VALUE oldclass = 0;
 	    VALUE data;
 
@@ -1847,8 +1848,8 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1848
 		append_extmod(v, extmod);
             }
 	    if (!rb_obj_respond_to(v, s_mload, TRUE)) {
-		rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'",
-			 rb_class2name(klass));
+		rb_raise(rb_eTypeError, "instance of %"PRIsVALUE" needs to have method `marshal_load'",
+			 name);
 	    }
 	    v = r_entry(v, arg);
 	    data = r_object(arg);
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 50332)
+++ test/ruby/test_marshal.rb	(revision 50333)
@@ -684,4 +684,15 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L684
       Marshal.load(d)
     }
   end
+
+  def test_unloadable_usrmarshal
+    c = eval("class UsrMarshal\u{23F0 23F3}<Time;self;end")
+    c.class_eval {
+      alias marshal_dump _dump
+    }
+    d = Marshal.dump(c.new)
+    assert_raise_with_message(TypeError, /UsrMarshal\u{23F0 23F3}/) {
+      Marshal.load(d)
+    }
+  end
 end

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

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