Skip to content

Commit 8822969

Browse files
committed
Fix YAML loading
Psych (aka YAML) 4.x included a breaking change to how `YAML.load` works In Psych 4.0, `load` calls `safe_load` under the hood, and is therefore "safe" by default, but that breaks configurations that support (among other things) aliases, which are disabled when using "safe" loading. `unsafe_load` is now the canonical way to load trusted documents (i.e., config files): ruby/psych#533 (comment) To ensure maximum compatibility with old versions of Psych, we also need to set a minimum version of Psych to ensure `unsafe_load` is defined. The methods were introduced in v3.3.2: ruby/psych@cb50aa8 Resolves #116
1 parent 6206df2 commit 8822969

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

action_subscriber.gemspec

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
2+
lib = File.expand_path("../lib", __FILE__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require 'action_subscriber/version'
4+
require "action_subscriber/version"
55

66
Gem::Specification.new do |spec|
77
spec.name = "action_subscriber"
@@ -18,17 +18,18 @@ Gem::Specification.new do |spec|
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ["lib"]
2020

21-
spec.add_dependency 'activesupport', '>= 3.2'
21+
spec.add_dependency "activesupport", ">= 3.2"
2222

23-
if ENV['PLATFORM'] == "java" || ::RUBY_PLATFORM == 'java'
23+
if ENV["PLATFORM"] == "java" || ::RUBY_PLATFORM == "java"
2424
spec.platform = "java"
25-
spec.add_dependency 'march_hare', '~> 4.4'
25+
spec.add_dependency "march_hare", "~> 4.4"
2626
else
27-
spec.add_dependency 'bunny', '>= 1.5.0'
27+
spec.add_dependency "bunny", ">= 1.5.0"
2828
end
29-
spec.add_dependency 'concurrent-ruby'
30-
spec.add_dependency 'middleware'
31-
spec.add_dependency 'thor'
29+
spec.add_dependency "concurrent-ruby"
30+
spec.add_dependency "middleware"
31+
spec.add_dependency "psych", ">= 3.3.2"
32+
spec.add_dependency "thor"
3233

3334
spec.add_development_dependency "active_publisher", "~> 0.1.5"
3435
spec.add_development_dependency "activerecord", ">= 3.2"

lib/action_subscriber/configuration.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ def self.configure_from_yaml_and_cli(cli_options = {}, reload = false)
6969
absolute_config_path = ::File.expand_path(::File.join("config", "action_subscriber.yml"))
7070
if ::File.exists?(absolute_config_path)
7171
erb = ::ERB.new(::File.read(absolute_config_path)).result
72-
if defined?(SafeYAML)
73-
yaml_config = ::YAML.load(erb, :safe => true)[env]
74-
else
75-
yaml_config = ::YAML.load(erb)[env]
76-
end
72+
# Defined in Psych 3.2+ and the new canonical way to load trusted documents:
73+
# https://github.com/ruby/psych/issues/533#issuecomment-1019363688
74+
yaml_config = ::YAML.unsafe_load(erb)[env]
7775
end
7876

7977
::ActionSubscriber::Configuration::DEFAULTS.each_pair do |key, value|

0 commit comments

Comments
 (0)