Skip to content

Commit

Permalink
Move the YAML hook closer to init_with.
Browse files Browse the repository at this point in the history
Looked odd, so completely detached from the other necessary part of
the implementation.
  • Loading branch information
kaspth committed Aug 2, 2016
1 parent 0e0cff0 commit b71732c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Expand Up @@ -9,14 +9,6 @@
require 'set'
require 'yaml'

# Wire up YAML format compatibility with Rails 4.2. Makes the YAML parser call
# `init_with` when it encounters `!ruby/hash-with-ivars:ActionController::Parameters`,
# instead of trying to parse it as a regular hash subclass.
# Second `load_tags` is for compatibility with Psych prior to 2.0.9 where hashes
# were dumped without instance variables.
YAML.load_tags['!ruby/hash-with-ivars:ActionController::Parameters'] = 'ActionController::Parameters'
YAML.load_tags['!ruby/hash:ActionController::Parameters'] = 'ActionController::Parameters'

module ActionController
# Raised when a required parameter is missing.
#
Expand Down Expand Up @@ -600,6 +592,15 @@ def inspect
"<#{self.class} #{@parameters} permitted: #{@permitted}>"
end

def self.hook_into_yaml_loading # :nodoc:
# Wire up YAML format compatibility with Rails 4.2 and Psych 2.0.8 and 2.0.9+.
# Makes the YAML parser call `init_with` when it encounters the keys below
# instead of trying its own parsing routines.
YAML.load_tags['!ruby/hash-with-ivars:ActionController::Parameters'] = name
YAML.load_tags['!ruby/hash:ActionController::Parameters'] = name
end
hook_into_yaml_loading

def init_with(coder) # :nodoc:
case coder.tag
when '!ruby/hash:ActionController::Parameters'
Expand Down

0 comments on commit b71732c

Please sign in to comment.