Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rack::Utils#normalize_params should be ignorant of the provided param…

…s class.
  • Loading branch information...
commit 1a6a57c9d7fdd5f60397422b040f02edf30c1538 1 parent 7bb8d20
@thedarkone authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 lib/rack/utils.rb
View
13 lib/rack/utils.rb
@@ -111,14 +111,14 @@ def normalize_params(params, name, v = nil)
child_key = $1
params[k] ||= []
raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
- if params[k].last.is_a?(KeySpaceConstrainedParams) && !params[k].last.key?(child_key)
+ if params_hash_type?(params[k].last) && !params[k].last.key?(child_key)
normalize_params(params[k].last, child_key, v)
else
- params[k] << normalize_params(KeySpaceConstrainedParams.new, child_key, v)
+ params[k] << normalize_params(params.class.new, child_key, v)
end
else
- params[k] ||= KeySpaceConstrainedParams.new
- raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(KeySpaceConstrainedParams)
+ params[k] ||= params.class.new
+ raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k])
params[k] = normalize_params(params[k], after, v)
end
@@ -126,6 +126,11 @@ def normalize_params(params, name, v = nil)
end
module_function :normalize_params
+ def params_hash_type?(obj)
+ obj.kind_of?(KeySpaceConstrainedParams) || obj.kind_of?(Hash)
+ end
+ module_function :params_hash_type?
+
def build_query(params)
params.map { |k, v|
if v.class == Array
Please sign in to comment.
Something went wrong with that request. Please try again.