diff options
author | Alexander Momchilov <alexander.momchilov@shopify.com> | 2022-07-21 15:07:39 -0400 |
---|---|---|
committer | Alexander Momchilov <alexander.momchilov@shopify.com> | 2022-07-27 15:24:24 -0400 |
commit | 0c11ddcf4636cfa415a2d4ff5a5222830605b086 (patch) | |
tree | 72d21f3d0e2755d4a0601fd5f9d69cfb6b2a672c /lib | |
parent | b9ab19094f1534c38b724a2ef76c30eb9cf5262f (diff) | |
download | psych-0c11ddcf4636cfa415a2d4ff5a5222830605b086.tar.gz |
Raise specific error when aliases are not enabled
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych.rb | 2 | ||||
-rw-r--r-- | lib/psych/exception.rb | 7 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index 42d79ef..4a2ab58 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -307,7 +307,7 @@ module Psych # A Psych::DisallowedClass exception will be raised if the yaml contains a # class that isn't in the +permitted_classes+ list. # - # A Psych::BadAlias exception will be raised if the yaml contains aliases + # A Psych::AliasesNotEnabled exception will be raised if the yaml contains aliases # but the +aliases+ keyword argument is set to false. # # +filename+ will be used in the exception message if any exception is raised diff --git a/lib/psych/exception.rb b/lib/psych/exception.rb index f473b95..04a9a90 100644 --- a/lib/psych/exception.rb +++ b/lib/psych/exception.rb @@ -6,6 +6,13 @@ module Psych class BadAlias < Exception end + # Subclasses `BadAlias` for backwards compatibility + class AliasesNotEnabled < BadAlias + def initialize + super "Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`." + end + end + class DisallowedClass < Exception def initialize action, klass_name super "Tried to #{action} unspecified class: #{klass_name}" diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 935bc74..0bf5198 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -427,7 +427,7 @@ module Psych class NoAliasRuby < ToRuby def visit_Psych_Nodes_Alias o - raise BadAlias, "Unknown alias: #{o.anchor}" + raise AliasesNotEnabled end end end |