diff options
author | Daniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org> | 2019-12-14 14:45:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-14 14:45:21 -0500 |
commit | b0161f545a9a9e68d3996df21f949b77edb81221 (patch) | |
tree | 081b59b732b150e926b28e166ed26d124702bdfe | |
parent | 9c6b5c860aa77bdfaaf416c5c098536b7e2eed5c (diff) | |
parent | 0d085afd391193a63c005b8f0fef5ed4be79910c (diff) | |
download | hashie-b0161f545a9a9e68d3996df21f949b77edb81221.tar.gz |
Merge pull request #505 from michaelherold/fix-multiple-array-conversion
Ensure that Hashie::Arrays are not deconverted
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/hashie/mash.rb | 2 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 9 |
3 files changed, 10 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b46c63..d1edf2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ scheme are considered to be bugs. ### Fixed * [#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). * Your contribution here. ### Security diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index f832e98..97d6fa6 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -382,8 +382,6 @@ module Hashie when ::Hash val = val.dup if duping self.class.new(val) - when Array - val.map { |e| convert_value(e) } when ::Array Array.new(val.map { |e| convert_value(e) }) else diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index fa4e47b..4629124 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -982,6 +982,7 @@ describe Hashie::Mash do with_minimum_ruby('2.3.0') do describe '#dig' do subject { described_class.new(a: { b: 1 }) } + it 'accepts both string and symbol as key' do expect(subject.dig(:a, :b)).to eq(1) expect(subject.dig('a', 'b')).to eq(1) @@ -994,6 +995,14 @@ describe Hashie::Mash do expect(subject.dig('1', :b)).to eq(1) end end + + context 'when the Mash wraps a Hashie::Array' do + it 'handles digging into an array' do + mash = described_class.new(alphabet: { first_three: Hashie::Array['a', 'b', 'c'] }) + + expect(mash.dig(:alphabet, :first_three, 0)).to eq 'a' + end + end end end |