Skip to content

Commit

Permalink
Fix compatibility with Psych 4
Browse files Browse the repository at this point in the history
Psych 4 load in safe mode by default:
ruby/psych#487

So aliases need to be explicitly allowed
  • Loading branch information
byroot committed May 18, 2021
1 parent 34c02ff commit ceaf826
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
19 changes: 15 additions & 4 deletions lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,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 " \
Expand All @@ -107,8 +111,15 @@ 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

def globbed_path_with_extensions(path)
Expand Down
6 changes: 5 additions & 1 deletion lib/webpacker/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ceaf826

Please sign in to comment.