summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Herold <github@michaeljherold.com>2018-09-10 08:03:14 -0500
committerGitHub <noreply@github.com>2018-09-10 08:03:14 -0500
commit7ed267b64c03aaef32bbb756a21a18fd2d4504f0 (patch)
treea531e1b8731acb1898bc4e6843f7d8ae0a1de25a
parent4893ca938e243acb07513c3c8b773acf26f72be6 (diff)
parent6992fd1327f3aa3c443b97b698a1007b1d955bf1 (diff)
downloadhashie-7ed267b64c03aaef32bbb756a21a18fd2d4504f0.tar.gz
Fix a regression with aliases on `Mash.load` (#459)
By switching to `YAML.safe_load`, we accidentally regressed the behavior of `Mash.load` by limiting the use of aliases within the YAML file. This restores the original behavior, but still uses `YAML.safe_load`.
-rw-r--r--.rubocop_todo.yml6
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/hashie/extensions/parsers/yaml_erb_parser.rb2
-rw-r--r--spec/fixtures/yaml_with_aliases.yml11
-rw-r--r--spec/hashie/mash_spec.rb8
5 files changed, 24 insertions, 4 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index e4e05c7..5d3da74 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2018-08-11 15:53:09 -0500 using RuboCop version 0.52.1.
+# on 2018-08-14 21:37:22 -0500 using RuboCop version 0.52.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -13,7 +13,7 @@ Metrics/AbcSize:
# Offense count: 58
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
- Max: 620
+ Max: 626
# Offense count: 2
# Configuration parameters: CountComments.
@@ -48,7 +48,7 @@ Style/IfUnlessModifier:
Exclude:
- 'lib/hashie/extensions/strict_key_access.rb'
-# Offense count: 261
+# Offense count: 263
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ebebbb1..1cfbe5e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ scheme are considered to be bugs.
### Fixed
+* [#459](https://github.com/intridea/hashie/pull/459): Fixed a regression in `Mash.load` that disallowed aliases - [@arekt](https://github.com/arekt) and [@michaelherold](https://github.com/michaelherold).
* 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 c2808de..d3b5c80 100644
--- a/lib/hashie/extensions/parsers/yaml_erb_parser.rb
+++ b/lib/hashie/extensions/parsers/yaml_erb_parser.rb
@@ -14,7 +14,7 @@ module Hashie
def perform
template = ERB.new(@content)
template.filename = @file_path
- YAML.safe_load template.result
+ YAML.safe_load template.result, [], [], true
end
def self.perform(file_path)
diff --git a/spec/fixtures/yaml_with_aliases.yml b/spec/fixtures/yaml_with_aliases.yml
new file mode 100644
index 0000000..f442c03
--- /dev/null
+++ b/spec/fixtures/yaml_with_aliases.yml
@@ -0,0 +1,11 @@
+accounts: &base_accounts
+ admin:
+ password: secret
+
+company_a:
+ accounts: &accounts
+ <<: *base_accounts
+
+# company_b:
+# accounts: &accounts
+# <<: *base_accounts
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index 680f403..b46bd6c 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -694,6 +694,14 @@ describe Hashie::Mash do
expect(subject.object_id).to eq subject.object_id
end
end
+
+ context 'when the file has aliases in it' do
+ it 'can use the aliases and does not raise an error' do
+ mash = Hashie::Mash.load('spec/fixtures/yaml_with_aliases.yml')
+
+ expect(mash.company_a.accounts.admin.password).to eq('secret')
+ end
+ end
end
describe '#to_module(mash_method_name)' do