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

ruby-changes:38251

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

nobu	2015-04-16 23:25:33 +0900 (Thu, 16 Apr 2015)

  New Revision: 50332

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

  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 USERDEF without _load
      singleton method.

  Modified files:
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb
Index: marshal.c
===================================================================
--- marshal.c	(revision 50331)
+++ marshal.c	(revision 50332)
@@ -1815,12 +1815,13 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1815
 
       case TYPE_USERDEF:
         {
-	    VALUE klass = path2class(r_unique(arg));
+	    VALUE name = r_unique(arg);
+	    VALUE klass = path2class(name);
 	    VALUE data;
 
 	    if (!rb_obj_respond_to(klass, s_load, TRUE)) {
-		rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
-			 rb_class2name(klass));
+		rb_raise(rb_eTypeError, "class %"PRIsVALUE" needs to have method `_load'",
+			 name);
 	    }
 	    data = r_string(arg);
 	    if (ivp) {
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 50331)
+++ test/ruby/test_marshal.rb	(revision 50332)
@@ -673,4 +673,15 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L673
       Marshal.load(d)
     }
   end
+
+  def test_unloadable_userdef
+    c = eval("class Userdef\u{23F0 23F3}<Time;self;end")
+    class << c
+      undef _load
+    end
+    d = Marshal.dump(c.new)
+    assert_raise_with_message(TypeError, /Userdef\u{23F0 23F3}/) {
+      Marshal.load(d)
+    }
+  end
 end

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

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