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

ruby-changes:23607

From: tenderlove <ko1@a...>
Date: Wed, 16 May 2012 05:13:49 +0900 (JST)
Subject: [ruby-changes:23607] tenderlove:r35658 (trunk): * ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string

tenderlove	2012-05-16 05:13:21 +0900 (Wed, 16 May 2012)

  New Revision: 35658

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

  Log:
    * ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
      subclass dumping and loading.
    
    * test/psych/test_array.rb: pertinent tests
    
    * test/psych/test_string.rb: ditto

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/to_ruby.rb
    trunk/test/psych/test_array.rb
    trunk/test/psych/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35657)
+++ ChangeLog	(revision 35658)
@@ -1,3 +1,12 @@
+Wed May 16 05:11:29 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
+	  subclass dumping and loading.
+
+	* test/psych/test_array.rb: pertinent tests
+
+	* test/psych/test_string.rb: ditto
+
 Wed May 16 01:31:21 2012  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
Index: ext/psych/lib/psych/visitors/to_ruby.rb
===================================================================
--- ext/psych/lib/psych/visitors/to_ruby.rb	(revision 35657)
+++ ext/psych/lib/psych/visitors/to_ruby.rb	(revision 35658)
@@ -147,8 +147,7 @@
           string = members.delete 'str'
 
           if klass
-            string = klass.allocate
-            string.replace string
+            string = klass.allocate.replace string
           end
 
           init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
Index: test/psych/test_array.rb
===================================================================
--- test/psych/test_array.rb	(revision 35657)
+++ test/psych/test_array.rb	(revision 35658)
@@ -14,6 +14,16 @@
       @list = [{ :a => 'b' }, 'foo']
     end
 
+    def test_another_subclass_with_attributes
+      y = Y.new.tap {|y| y.val = 1}
+      y << "foo" << "bar"
+      y = Psych.load Psych.dump y
+
+      assert_equal %w{foo bar}, y
+      assert_equal Y, y.class
+      assert_equal 1, y.val
+    end
+
     def test_subclass
       yaml = Psych.dump X.new
       assert_match X.name, yaml
Index: test/psych/test_string.rb
===================================================================
--- test/psych/test_string.rb	(revision 35657)
+++ test/psych/test_string.rb	(revision 35658)
@@ -9,6 +9,13 @@
       attr_accessor :val
     end
 
+    def test_another_subclass_with_attributes
+      y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
+      assert_equal "foo", y
+      assert_equal Y, y.class
+      assert_equal 1, y.val
+    end
+
     def test_backwards_with_syck
       x = Psych.load "--- !str:#{X.name} foo\n\n"
       assert_equal X, x.class

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

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