From 1e0477f570431e836fe49d54c8b6878a0661864d Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Sun, 30 Oct 2011 12:36:09 -0700 Subject: [PATCH] simplify handling of captures --- lib/sinatra/base.rb | 17 ++--------------- test/routing_test.rb | 3 ++- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 81fbfd57..af3a7c0a 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -802,21 +802,8 @@ module Sinatra 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 diff --git a/test/routing_test.rb b/test/routing_test.rb index e3f4d0be..a29b3c0f 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -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