lib/rack/app/params.rb in rack-app-6.5.0 vs lib/rack/app/params.rb in rack-app-6.6.0
- old
+ new
@@ -25,24 +25,36 @@
def initialize(env)
@env = env
end
def generate_query_params
- raw_cgi_params.reduce({}) do |params_collection, (k, v)|
- params_collection[k.sub(/\[\]$/, '')] = formatted_value(k, v)
+ raw_rack_formatted_params.reduce({}) do |params_collection, (k, v)|
+ params_collection[k.sub(/\[\]$/, '')] = v
params_collection
end
end
+ def single_paramter_value?(v)
+ v.is_a?(Array) && v.length === 1
+ end
+
def formatted_value(key, value)
- single_paramter_value?(value) && !key.end_with?("[]") ? value[0] : value
+ single_paramter_value?(value) && !key.end_with?('[]') ? value[0] : value
end
- def single_paramter_value?(v)
- v.is_a?(Array) and v.length === 1
+ def query_string
+ @env[::Rack::QUERY_STRING]
end
- def raw_cgi_params
- CGI.parse(@env[::Rack::QUERY_STRING].to_s)
+ def raw_rack_formatted_params
+ ::Rack::Utils.parse_nested_query(query_string).merge!(params_that_presented_multiple_times)
end
+ def params_that_presented_multiple_times
+ cgi_params = CGI.parse(query_string)
+ cgi_params.reject! { |k, v| v.length == 1 && k !~ /^\w+$/ }
+ cgi_params.reduce({}) do |result, (key, value)|
+ result[key] = formatted_value(key, value)
+ result
+ end
+ end
end