Skip to content

Commit

Permalink
Ruby master ships with Psych 4.0.0 which makes YAML.load
Browse files Browse the repository at this point in the history
defaults to safe mode (ruby/psych#487).

Keep compatibility by using unsafe_load.

From: settingslogic#21
Also: https://stackoverflow.com/a/71192990
  • Loading branch information
charger committed Jul 26, 2022
1 parent 463073f commit dcf56e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/settingslogic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ def initialize(hash_or_file = self.class.source, section = nil)
self.replace hash_or_file
else
file_contents = open(hash_or_file).read
hash = file_contents.empty? ? {} : YAML.load(ERB.new(file_contents).result).to_hash
hash = if file_contents.empty?
{}
else
payload = ERB.new(file_contents).result
(YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(payload) : YAML.load(payload)).to_hash
end
if self.class.namespace
hash = hash[self.class.namespace] or return missing_key("Missing setting '#{self.class.namespace}' in #{hash_or_file}")
end
Expand Down

0 comments on commit dcf56e5

Please sign in to comment.