summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaerti Papa <laerti.papa@xing.com>2018-09-30 14:00:12 +0200
committerLaerti Papa <laerti.papa@xing.com>2018-10-02 17:06:46 +0200
commit209f8afd84b987e33c53dce1cb7e138461054a41 (patch)
tree5947ee0a52f18c9d9bda8676bfc96237943b5b91
parent506c385ccc034eaf1e3420ce9940749b3acdc42b (diff)
downloadhashie-209f8afd84b987e33c53dce1cb7e138461054a41.tar.gz
Do not call any reader attribute in Mash#update if key does not exist
Refs: https://github.com/intridea/hashie/issues/464
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/hashie/mash.rb2
-rw-r--r--spec/hashie/mash_spec.rb9
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 775779c..b25e660 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,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).
+* [#465](https://github.com/intridea/hashie/pull/465): Fixed `deep_update` to call any readers when a key exists - [@laertispappas](https://github.com/laertispappas).
* Your contribution here.
### Security
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index 02ccc3f..37a903f 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -214,7 +214,7 @@ module Hashie
def deep_update(other_hash, &blk)
other_hash.each_pair do |k, v|
key = convert_key(k)
- if regular_reader(key).is_a?(Mash) && v.is_a?(::Hash)
+ if key?(key) && regular_reader(key).is_a?(Mash) && v.is_a?(::Hash)
custom_reader(key).deep_update(v, &blk)
else
value = convert_value(v, true)
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index c6f4516..be82281 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -241,6 +241,15 @@ describe Hashie::Mash do
expect(duped.details.address).to eq 'Nowhere road'
expect(duped.details.state).to eq 'West Thoughtleby'
end
+
+ it 'does not raise an exception when default_proc raises an error' do
+ hash = described_class.new(a: 1) { |_k, _v| raise('Should not be raise I') }
+ other_has = described_class.new(a: 2, b: 2) { |_k, _v| raise('Should not be raise II') }
+ expected_hash = described_class.new(a: 2, b: 2)
+
+ res = hash.merge(other_has)
+ expect(res).to eq(expected_hash)
+ end
end
describe 'shallow update' do