diff options
author | Daniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org> | 2020-01-13 15:31:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-13 15:31:38 -0500 |
commit | a1fa33d4259079f434b6d0820562e670d446582f (patch) | |
tree | 0f6567726e4fef32198c4fdce744db4af21b54a8 | |
parent | b0161f545a9a9e68d3996df21f949b77edb81221 (diff) | |
parent | 3e8760652c16912b358af307b55c474d5521ba8f (diff) | |
download | hashie-a1fa33d4259079f434b6d0820562e670d446582f.tar.gz |
Merge pull request #507 from koic/suppress_warn_for_psych_3_1_0_or_higher
Suppress `Psych.safe_load` arg warn when using Psych 3.1.0+
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/hashie/extensions/parsers/yaml_erb_parser.rb | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d1edf2c..1675557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ scheme are considered to be bugs. * [#467](https://github.com/intridea/hashie/pull/467): Fixed `DeepMerge#deep_merge` mutating nested values within the receiver - [@michaelherold](https://github.com/michaelherold). * [#505](https://github.com/hashie/hashie/pull/505): Ensure that `Hashie::Array`s are not deconverted within `Hashie::Mash`es to make `Mash#dig` work properly - [@michaelherold](https://github.com/michaelherold). +* [#507](https://github.com/hashie/hashie/pull/507): Suppress `Psych.safe_load` arg warn when using Psych 3.1.0+ - [@koic](https://github.com/koic). * Your contribution here. ### Security diff --git a/lib/hashie/extensions/parsers/yaml_erb_parser.rb b/lib/hashie/extensions/parsers/yaml_erb_parser.rb index 6a259cb..ed9ae4f 100644 --- a/lib/hashie/extensions/parsers/yaml_erb_parser.rb +++ b/lib/hashie/extensions/parsers/yaml_erb_parser.rb @@ -18,13 +18,30 @@ module Hashie permitted_classes = @options.fetch(:permitted_classes) { [] } permitted_symbols = @options.fetch(:permitted_symbols) { [] } aliases = @options.fetch(:aliases) { true } - # TODO: Psych in newer rubies expects these args to be keyword args. - YAML.safe_load template.result, permitted_classes, permitted_symbols, aliases + + yaml_safe_load(template, permitted_classes, permitted_symbols, aliases) end def self.perform(file_path, options = {}) new(file_path, options).perform end + + private + + if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0') # Ruby 2.6+ + def yaml_safe_load(template, permitted_classes, permitted_symbols, aliases) + YAML.safe_load( + template.result, + permitted_classes: permitted_classes, + permitted_symbols: permitted_symbols, + aliases: aliases + ) + end + else + def yaml_safe_load(template, permitted_classes, permitted_symbols, aliases) + YAML.safe_load(template.result, permitted_classes, permitted_symbols, aliases) + end + end end end end |