Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use YAML safe load with aliases with Psych gem version >= 4.0 #295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ branches:
only:
- master
gemfile:
- gemfiles/rails52.gemfile
- gemfiles/rails60.gemfile
- gemfiles/rails6.gemfile
- gemfiles/rails61.gemfile
- gemfiles/rails70.gemfile
- gemfiles/rails71.gemfile
jobs:
allow_failures:
- rvm: ruby-head
- gemfile: gemfiles/rails6.gemfile
- rvm: '3.3'
gemfile: gemfiles/rails61.gemfile
- rvm: '3.2'
gemfile: gemfiles/rails61.gemfile

language: ruby
rvm:
- "2.5"
- "2.6"
- "2.7"
- ruby-head
- "3.0"
- "3.1"
- "3.2"
- "3.3"
script: bundle exec rspec
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source "https://rubygems.org"

gemspec

gem "rails", ">= 5.2.0", "< 6.1"
gem "rails", ">= 5.2.0", "< 7.2"

group :test do
gem "aruba", "~> 1.0"
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails6.gemfile → gemfiles/rails61.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source "https://rubygems.org"

gemspec path: ".."

gem "rails", "~> 6.0"
gem "rails", "~> 6.1"

group :test do
gem "aruba", "~> 1.0"
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails52.gemfile → gemfiles/rails70.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source "https://rubygems.org"

gemspec path: ".."

gem "rails", "~> 5.2.0"
gem "rails", "~> 7.0"

group :test do
gem "aruba", "~> 1.0"
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails60.gemfile → gemfiles/rails71.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source "https://rubygems.org"

gemspec path: ".."

gem "rails", "~> 6.0.0"
gem "rails", "~> 7.1"

group :test do
gem "aruba", "~> 1.0"
Expand Down
11 changes: 10 additions & 1 deletion lib/figaro/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ 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

result = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("4")
YAML.safe_load(payload, aliases: true)
else
YAML.load(payload)
end
result || {}
end

def global_configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/figaro/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_configuration
end

def ignore_configuration
if File.exists?(".gitignore")
if File.exist?(".gitignore")
append_to_file(".gitignore", <<-EOF)

# Ignore application 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
10 changes: 9 additions & 1 deletion spec/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
describe Figaro::Rails do
before do
rails_spec = Bundler.locked_gems.specs.find { |spec| spec.name == "rails" }
skip_asset_pipeline_option =
if rails_spec.version >= Gem::Version.new("7.0.0")
"--skip-asset-pipeline"
else
"--skip-sprockets"
end

run_command_and_stop(<<-CMD)
rails new example \
--skip-gemfile \
--skip-git \
--skip-keeps \
--skip-sprockets \
#{skip_asset_pipeline_option} \
--skip-spring \
--skip-listen \
--skip-javascript \
Expand Down