From 6d4f184bb4fa2457564c9f26bc6ce72c7fd64dfc Mon Sep 17 00:00:00 2001 From: john hernandez Date: Tue, 18 May 2021 09:41:55 +0200 Subject: [PATCH] Fix compatibility with Psych 4 Psych 4 load in safe mode by default: https://github.com/ruby/psych/pull/487 So aliases need to be explicitly allowed --- lib/webpacker/configuration.rb | 19 +++++++++++++++---- lib/webpacker/env.rb | 6 +++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/webpacker/configuration.rb b/lib/webpacker/configuration.rb index 2e3170a..df7f87b 100644 --- a/lib/webpacker/configuration.rb +++ b/lib/webpacker/configuration.rb @@ -73,8 +73,12 @@ def data end def load - YAML.load(config_path.read)[env].deep_symbolize_keys - + config = begin + YAML.load_file(config_path.to_s, aliases: true) + rescue ArgumentError + YAML.load_file(config_path.to_s) + end + config[env].deep_symbolize_keys rescue Errno::ENOENT => e raise "Webpacker configuration file not found #{config_path}. " \ "Please run rails webpacker:install " \ @@ -87,7 +91,14 @@ def load end def defaults - @defaults ||= \ - HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env]) + @defaults ||= begin + path = File.expand_path("../../install/config/webpacker.yml", __FILE__) + config = begin + YAML.load_file(path, aliases: true) + rescue ArgumentError + YAML.load_file(path) + end + HashWithIndifferentAccess.new(config[env]) + end end end diff --git a/lib/webpacker/env.rb b/lib/webpacker/env.rb index 8e54825..e5cc58c 100644 --- a/lib/webpacker/env.rb +++ b/lib/webpacker/env.rb @@ -27,7 +27,11 @@ def fallback_env_warning def available_environments if config_path.exist? - YAML.load(config_path.read).keys + begin + YAML.load_file(config_path.to_s, aliases: true) + rescue ArgumentError + YAML.load_file(config_path.to_s) + end else [].freeze end