get '/' should match even if PATH_INFO is empty. This fixes compatibility with Rails 3.

Signed-off-by: Simon Rozet <simon@rozet.name>
This commit is contained in:
José Valim 2010-07-06 20:32:18 +02:00 committed by Simon Rozet
parent f513df6bd4
commit 75d74a413a
2 changed files with 15 additions and 1 deletions

View File

@ -466,7 +466,9 @@ module Sinatra
def route!(base=self.class, pass_block=nil)
if routes = base.routes[@request.request_method]
original_params = @params
path = unescape(@request.path_info)
path = unescape(@request.path_info)
path = "/" if path.empty?
routes.each do |pattern, keys, conditions, block|
if match = pattern.match(path)

View File

@ -84,6 +84,18 @@ class RoutingTest < Test::Unit::TestCase
assert_equal "<h1>Not Found</h1>", response.body
end
it 'matches empty PATH_INFO to "/"' do
mock_app {
get '/' do
'worked'
end
}
get '/', {}, "PATH_INFO" => ""
assert ok?
assert_equal 'worked', body
end
it 'takes multiple definitions of a route' do
mock_app {
user_agent(/Foo/)