Skip to content

Commit

Permalink
simplify handling of captures
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Oct 30, 2011
1 parent fe34d41 commit 1e0477f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
17 changes: 2 additions & 15 deletions lib/sinatra/base.rb
Expand Up @@ -802,21 +802,8 @@ def process_route(pattern, keys, conditions, block = nil, values = [])
route = '/' if route.empty? and not settings.empty_path_info?
if match = pattern.match(route)
values += match.captures.to_a.map { |v| force_encoding URI.decode(v) if v }
params =
if keys.any?
keys.zip(values).inject({}) do |hash,(k,v)|
if k == 'splat'
(hash[k] ||= []) << v
else
hash[k] = v
end
hash
end
elsif values.any?
{'captures' => values}
else
{}
end
params = {'splat' => [], 'captures' => values}
keys.zip(values) { |k,v| (params[k] ||= '') << v if v }
@params = @original_params.merge(params)
@block_params = values
catch(:pass) do
Expand Down
3 changes: 2 additions & 1 deletion test/routing_test.rb
Expand Up @@ -370,7 +370,8 @@ class RoutingTest < Test::Unit::TestCase
"firefox" => {"engine" => {"name"=>"spidermonkey", "version"=>"1.7.0"}},
"chrome" => {"engine" => {"name"=>"V8", "version"=>"1.0"}}
},
"paste" => {"name"=>"hello world", "syntax"=>"ruby"}
"paste" => {"name"=>"hello world", "syntax"=>"ruby"},
"splat"=>[], "captures"=>[]
}
mock_app {
get '/foo' do
Expand Down

0 comments on commit 1e0477f

Please sign in to comment.