зеркало из https://github.com/github/ruby.git
[ruby/psych] Raise specific error when an anchor isn't defined
https://github.com/ruby/psych/commit/98fbd5247a
This commit is contained in:
Родитель
4b9cdf4e1c
Коммит
9c13a6ce5f
|
@ -13,6 +13,13 @@ module Psych
|
|||
end
|
||||
end
|
||||
|
||||
# Subclasses `BadAlias` for backwards compatibility
|
||||
class AnchorNotDefined < BadAlias
|
||||
def initialize anchor_name
|
||||
super "An alias referenced an unknown anchor: #{anchor_name}"
|
||||
end
|
||||
end
|
||||
|
||||
class DisallowedClass < Exception
|
||||
def initialize action, klass_name
|
||||
super "Tried to #{action} unspecified class: #{klass_name}"
|
||||
|
|
|
@ -323,7 +323,7 @@ module Psych
|
|||
end
|
||||
|
||||
def visit_Psych_Nodes_Alias o
|
||||
@st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
|
||||
@st.fetch(o.anchor) { raise AnchorNotDefined, o.anchor }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -124,7 +124,7 @@ module Psych
|
|||
end
|
||||
|
||||
def test_raises_if_anchor_not_defined
|
||||
assert_raise(Psych::BadAlias) do
|
||||
assert_raise(Psych::AnchorNotDefined) do
|
||||
Psych.unsafe_load(<<~eoyml)
|
||||
---
|
||||
foo: &foo
|
||||
|
|
|
@ -117,7 +117,7 @@ development:
|
|||
bar:
|
||||
<< : *foo
|
||||
eoyml
|
||||
exp = assert_raise(Psych::BadAlias) { Psych.load(yaml, aliases: true) }
|
||||
exp = assert_raise(Psych::AnchorNotDefined) { Psych.load(yaml, aliases: true) }
|
||||
assert_match 'foo', exp.message
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче