From 0e0cff0f27eb76e84fd2226396f16bb52fe754bd Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 2 Aug 2016 15:53:45 +0200 Subject: Replace implicit formats with a case statement. The coder that Psych passes in has a `tag` method we can use to detect which serialization format we're reviving for. Use it and make it clearer alongside the `load_tags` fiddling. --- .../lib/action_controller/metal/strong_parameters.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index d2db982a6e..13e46789e9 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -601,19 +601,20 @@ module ActionController end def init_with(coder) # :nodoc: - if coder.map['elements'] - # YAML 2.0.9's Hash subclass format from Rails 4.2, where keys and values + case coder.tag + when '!ruby/hash:ActionController::Parameters' + # YAML 2.0.8's format where hash instance variables weren't stored. + @parameters = coder.map.with_indifferent_access + @permitted = false + when '!ruby/hash-with-ivars:ActionController::Parameters' + # YAML 2.0.9's Hash subclass format where keys and values # were stored under an elements hash and `permitted` within an ivars hash. @parameters = coder.map['elements'].with_indifferent_access @permitted = coder.map['ivars'][:@permitted] - elsif coder.map['parameters'] + when '!ruby/object:ActionController::Parameters' # YAML's Object format. Only needed because of the format # backwardscompability above, otherwise equivalent to YAML's initialization. @parameters, @permitted = coder.map['parameters'], coder.map['permitted'] - else - # YAML 2.0.8's format where hash instance variables weren't stored. - @parameters = coder.map.with_indifferent_access - @permitted = false end end -- cgit v1.2.3