summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/psych/lib/psych.rb3
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb2
-rw-r--r--test/psych/test_merge_keys.rb9
4 files changed, 22 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 89168937b6..c59cbeb1df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon Jul 18 13:36:47 2011 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * 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@ruby-lang.org>
* ext/curses/curses.c: added the new class Curses::Pad, which
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index 31d73c1f03..8a4d63a49c 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -98,6 +98,9 @@ module Psych
class Exception < RuntimeError
end
+ class BadAlias < Exception
+ end
+
autoload :Stream, 'psych/stream'
###
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index b8eb698754..fd899f65a6 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -201,7 +201,7 @@ module Psych
end
def visit_Psych_Nodes_Alias o
- @st[o.anchor]
+ @st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
end
private
diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb
index b3ebe9b463..bf5968ff86 100644
--- a/test/psych/test_merge_keys.rb
+++ b/test/psych/test_merge_keys.rb
@@ -2,6 +2,15 @@ require 'psych/helper'
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