Skip to content

Commit ceaf826

Browse files
committed
Fix compatibility with Psych 4
Psych 4 load in safe mode by default: ruby/psych#487 So aliases need to be explicitly allowed
1 parent 34c02ff commit ceaf826

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/webpacker/configuration.rb

+15-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ def data
9393
end
9494

9595
def load
96-
YAML.load(config_path.read)[env].deep_symbolize_keys
97-
96+
config = begin
97+
YAML.load_file(config_path.to_s, aliases: true)
98+
rescue ArgumentError
99+
YAML.load_file(config_path.to_s)
100+
end
101+
config[env].deep_symbolize_keys
98102
rescue Errno::ENOENT => e
99103
raise "Webpacker configuration file not found #{config_path}. " \
100104
"Please run rails webpacker:install " \
@@ -107,8 +111,15 @@ def load
107111
end
108112

109113
def defaults
110-
@defaults ||= \
111-
HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env])
114+
@defaults ||= begin
115+
path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
116+
config = begin
117+
YAML.load_file(path, aliases: true)
118+
rescue ArgumentError
119+
YAML.load_file(path)
120+
end
121+
HashWithIndifferentAccess.new(config[env])
122+
end
112123
end
113124

114125
def globbed_path_with_extensions(path)

lib/webpacker/env.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def fallback_env_warning
2727

2828
def available_environments
2929
if config_path.exist?
30-
YAML.load(config_path.read).keys
30+
begin
31+
YAML.load_file(config_path.to_s, aliases: true)
32+
rescue ArgumentError
33+
YAML.load_file(config_path.to_s)
34+
end
3135
else
3236
[].freeze
3337
end

0 commit comments

Comments
 (0)