Skip to content

Commit

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

Keep compatibility by using unsafe_load.
  • Loading branch information
alpaca-tc committed Jul 13, 2022
1 parent ffc9a46 commit 7eddfc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/figaro/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def raw_configuration
end

def parse(path)
File.exist?(path) && YAML.load(ERB.new(File.read(path)).result) || {}
return {} unless File.exist?(path)

payload = ERB.new(File.read(path)).result
(YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(payload) : YAML.load(payload)) || {}
end

def global_configuration
Expand Down
11 changes: 11 additions & 0 deletions spec/figaro/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ def yaml_to_path(yaml)
expect(application.configuration).to eq("foo" => "bar")
end

it "loads alias from YAML" do
application = Application.new(path: yaml_to_path(<<-YAML), environment: "development")
default: &defaults
foo: bar
development:
<<: *defaults
YAML

expect(application.configuration).to eq("foo" => "bar")
end

it "merges environment-specific values" do
application = Application.new(path: yaml_to_path(<<-YAML), environment: "test")
foo: bar
Expand Down

0 comments on commit 7eddfc2

Please sign in to comment.