Skip to content

Commit

Permalink
Base#nested params now backwards compat with Rack 0.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinH committed Apr 9, 2009
1 parent fa8dc93 commit 62ae8fc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/sinatra/base.rb
Expand Up @@ -473,8 +473,21 @@ def route_missing
# Recursively replace the params hash with a nested indifferent hash
def nested_params(params)
params = indifferent_hash.merge(params)
params.each do |key, value|
params[key] = Hash === value ? nested_params(value) : value
if params.keys.join.include?('[')
params.inject indifferent_hash do |res, (key,val)|
if key.include?('[')
head = key.split(/[\]\[]+/)
last = head.pop
head.inject(res){ |hash,k| hash[k] ||= indifferent_hash }[last] = val
else
res[key] = val
end
res
end
else
params.each do |key, value|
params[key] = Hash === value ? nested_params(value) : value
end
end
end

Expand Down

0 comments on commit 62ae8fc

Please sign in to comment.