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

ruby-changes:20530

From: tenderlove <ko1@a...>
Date: Mon, 18 Jul 2011 13:38:48 +0900 (JST)
Subject: [ruby-changes:20530] tenderlove:r32578 (trunk): * ext/psych/lib/psych.rb: define a new BadAlias error class.

tenderlove	2011-07-18 13:38:37 +0900 (Mon, 18 Jul 2011)

  New Revision: 32578

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

  Log:
    * ext/psych/lib/psych.rb: define a new BadAlias error class.
    * ext/psych/lib/psych/visitors/to_ruby.rb: raise an exception when
      deserializing an alias that does not exist.
    * test/psych/test_merge_keys.rb: corresponding test.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32577)
+++ ChangeLog	(revision 32578)
@@ -1,3 +1,12 @@
+Mon Jul 18 13:36:47 2011  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych.rb: define a new BadAlias error class.
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: raise an exception when
+	  deserializing an alias that does not exist.
+
+	* test/psych/test_merge_keys.rb: corresponding test.
+
 Mon Jul 18 00:00:46 2011  Shugo Maeda  <shugo@r...>
 
 	* ext/curses/curses.c: added the new class Curses::Pad, which
Index: ext/psych/lib/psych/visitors/to_ruby.rb
===================================================================
--- ext/psych/lib/psych/visitors/to_ruby.rb	(revision 32577)
+++ ext/psych/lib/psych/visitors/to_ruby.rb	(revision 32578)
@@ -201,7 +201,7 @@
       end
 
       def visit_Psych_Nodes_Alias o
-        @st[o.anchor]
+        @st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
       end
 
       private
Index: ext/psych/lib/psych.rb
===================================================================
--- ext/psych/lib/psych.rb	(revision 32577)
+++ ext/psych/lib/psych.rb	(revision 32578)
@@ -98,6 +98,9 @@
   class Exception < RuntimeError
   end
 
+  class BadAlias < Exception
+  end
+
   autoload :Stream, 'psych/stream'
 
   ###
Index: test/psych/test_merge_keys.rb
===================================================================
--- test/psych/test_merge_keys.rb	(revision 32577)
+++ test/psych/test_merge_keys.rb	(revision 32578)
@@ -2,6 +2,15 @@
 
 module Psych
   class TestMergeKeys < TestCase
+    def test_missing_merge_key
+      yaml = <<-eoyml
+bar:
+  << : *foo
+      eoyml
+      exp = assert_raises(Psych::BadAlias) { Psych.load yaml }
+      assert_match 'foo', exp.message
+    end
+
     # [ruby-core:34679]
     def test_merge_key
       yaml = <<-eoyml

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

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