summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/hashie/mash.rb2
-rw-r--r--spec/hashie/mash_spec.rb9
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