From 54219ae8c46bc431782caf01142883ce7e8b970b Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Thu, 21 Jul 2022 15:07:39 -0400 Subject: [ruby/psych] Raise specific error when aliases are not enabled https://github.com/ruby/psych/commit/0c11ddcf46 --- ext/psych/lib/psych/exception.rb | 7 +++++++ ext/psych/lib/psych/visitors/to_ruby.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/psych/lib/psych') diff --git a/ext/psych/lib/psych/exception.rb b/ext/psych/lib/psych/exception.rb index f473b95a3b..04a9a906a4 100644 --- a/ext/psych/lib/psych/exception.rb +++ b/ext/psych/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/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 935bc74f21..0bf5198ccc 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/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 -- cgit v1.2.3