This project is archived and is in readonly mode.

#2732 ✓stale
david.cizek (at gmail)

[PATCH] deep_merge does not work on HashWithIndifferentAccess

Reported by david.cizek (at gmail) | May 28th, 2009 @ 10:29 AM | in 2.3.10

When I have 2 hashes (HashWithIndifferntAccess) and do deep_merge, it seems that it do not merge.

(rdb:1) params {"submit"=>"Where", "action"=>"query", "controller"=>"locations", "query"=>{"text"=>"50,14"}} (rdb:1) params_new {:query=>{:type=>"coordinates"}, :location=>{:geo_attributes=>{:coordinates=>"50.0,14.0"}}}

(rdb:1) params_after_deep_merge {"submit"=>"Where", "action"=>"query", "controller"=>"locations", "query"=>{"type"=>"coordinates"}, "location"=>{"geo_attributes"=>{"coordinates"=>"50.0,14.0"}}}

(missing "query" => {"text" ...})

When both hashes are regular Hashes (not WithIndifferentAccess), they merge ok.

{"submit"=>"Where", "action"=>"query", "controller"=>"locations", "query"=>{"type"=>"coordinates", "text"=>"50,14"}, "location"=>{"geo_attributes"=>{"coordinates"=>"50.0,14.0"}}}

Rails 2.3.2, OS X

It seems that in
File vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb

line11:
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval

should be something like:

oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Referenced by

Pages