summary refs log tree commit
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2012-01-22 19:47:57 +0100
committerthedarkone <thedarkone2@gmail.com>2012-01-22 19:50:58 +0100
commit1a6a57c9d7fdd5f60397422b040f02edf30c1538 (patch)
tree47f3d878865cf633d4ffeea0df1a9c273cd81aaa
parent7bb8d20997eb2bd2bb1a160ab7bdef6aac55ecce (diff)
downloadrack-1a6a57c9d7fdd5f60397422b040f02edf30c1538.tar.gz
Rack::Utils#normalize_params should be ignorant of the provided params class.
-rw-r--r--lib/rack/utils.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index c1f71c0e..b706279d 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -111,14 +111,14 @@ module Rack
         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 @@ module Rack
     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