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

ruby-changes:35237

From: tenderlove <ko1@a...>
Date: Sat, 30 Aug 2014 06:41:36 +0900 (JST)
Subject: [ruby-changes:35237] tenderlove:r47319 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and

tenderlove	2014-08-30 06:41:02 +0900 (Sat, 30 Aug 2014)

  New Revision: 47319

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

  Log:
    * ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and
      loading. Fixes GH #85. Thanks @brentdax for the patch!
    * test/psych/test_exception.rb: test for fix

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/yaml_tree.rb
    trunk/test/psych/test_exception.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47318)
+++ ChangeLog	(revision 47319)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Aug 30 06:39:48 2014  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and
+	  loading. Fixes GH #85. Thanks @brentdax for the patch!
+	* test/psych/test_exception.rb: test for fix
+
 Sat Aug 30 06:23:40 2014  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/scalar_scanner.rb: fix loading strings that
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 47318)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 47319)
@@ -211,6 +211,25 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L211
         @emitter.end_mapping
       end
 
+      def visit_NameError o
+        tag = ['!ruby/exception', o.class.name].join ':'
+
+        @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
+
+        {
+          'message'   => o.message.to_s,
+          'backtrace' => private_iv_get(o, 'backtrace'),
+        }.each do |k,v|
+          next unless v
+          @emitter.scalar k, nil, nil, true, false, Nodes::Scalar::ANY
+          accept v
+        end
+
+        dump_ivars o
+
+        @emitter.end_mapping
+      end
+
       def visit_Regexp o
         register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
       end
Index: test/psych/test_exception.rb
===================================================================
--- test/psych/test_exception.rb	(revision 47318)
+++ test/psych/test_exception.rb	(revision 47319)
@@ -16,6 +16,12 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_exception.rb#L16
       @wups = Wups.new
     end
 
+    def test_naming_exception
+      err     = String.xxx rescue $!
+      new_err = Psych.load(Psych.dump(err))
+      assert_equal err.message, new_err.message
+    end
+
     def test_load_takes_file
       ex = assert_raises(Psych::SyntaxError) do
         Psych.load '--- `'

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

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