Skip to content
Browse files

Update bundled rack to fix more parameter parsing issues

  • Loading branch information...
1 parent 0cb020b commit 238a6bb62dc153743a0abc6eb1e35392ac799d65 @josh josh committed
View
4 actionpack/lib/action_controller/vendor/rack-1.0/rack/request.rb
@@ -108,7 +108,7 @@ def GET
else
@env["rack.request.query_string"] = query_string
@env["rack.request.query_hash"] =
- Utils.parse_query(query_string)
+ Utils.parse_nested_query(query_string)
end
end
@@ -129,7 +129,7 @@ def POST
form_vars.sub!(/\0\z/, '')
@env["rack.request.form_vars"] = form_vars
- @env["rack.request.form_hash"] = Utils.parse_query(form_vars)
+ @env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars)
begin
@env["rack.input"].rewind if @env["rack.input"].respond_to?(:rewind)
View
33 actionpack/lib/action_controller/vendor/rack-1.0/rack/utils.rb
@@ -29,19 +29,39 @@ def unescape(s)
# and ';' characters. You can also use this to parse
# cookies by changing the characters used in the second
# parameter (which defaults to '&;').
-
def parse_query(qs, d = '&;')
params = {}
(qs || '').split(/[#{d}] */n).each do |p|
k, v = unescape(p).split('=', 2)
- normalize_params(params, k, v)
+
+ if cur = params[k]
+ if cur.class == Array
+ params[k] << v
+ else
+ params[k] = [cur, v]
+ end
+ else
+ params[k] = v
+ end
end
return params
end
module_function :parse_query
+ def parse_nested_query(qs, d = '&;')
+ params = {}
+
+ (qs || '').split(/[#{d}] */n).each do |p|
+ k, v = unescape(p).split('=', 2)
+ normalize_params(params, k, v)
+ end
+
+ return params
+ end
+ module_function :parse_nested_query
+
def normalize_params(params, name, v = nil)
name =~ %r([\[\]]*([^\[\]]+)\]*)
k = $1 || ''
@@ -50,14 +70,7 @@ def normalize_params(params, name, v = nil)
return if k.empty?
if after == ""
- cur = params[k]
- if cur.is_a?(Array)
- params[k] << v
- elsif cur && name == $1
- params[k] = [cur, v]
- else
- params[k] = v
- end
+ params[k] = v
elsif after == "[]"
params[k] ||= []
raise TypeError unless params[k].is_a?(Array)

0 comments on commit 238a6bb

Please sign in to comment.
Something went wrong with that request. Please try again.