Merge pull request #1273 from namusyaka/support-trailing-slash
add :strict_paths option for managing trailing slashes
This commit is contained in:
commit
34521720b6
|
@ -1018,6 +1018,7 @@ module Sinatra
|
||||||
def process_route(pattern, conditions, block = nil, values = [])
|
def process_route(pattern, conditions, block = nil, values = [])
|
||||||
route = @request.path_info
|
route = @request.path_info
|
||||||
route = '/' if route.empty? and not settings.empty_path_info?
|
route = '/' if route.empty? and not settings.empty_path_info?
|
||||||
|
route = route[0..-2] if !settings.strict_paths? && route != '/' && route.end_with?('/')
|
||||||
return unless params = pattern.params(route)
|
return unless params = pattern.params(route)
|
||||||
|
|
||||||
params.delete("ignore") # TODO: better params handling, maybe turn it into "smart" object or detect changes
|
params.delete("ignore") # TODO: better params handling, maybe turn it into "smart" object or detect changes
|
||||||
|
@ -1819,6 +1820,7 @@ module Sinatra
|
||||||
set :absolute_redirects, true
|
set :absolute_redirects, true
|
||||||
set :prefixed_redirects, false
|
set :prefixed_redirects, false
|
||||||
set :empty_path_info, nil
|
set :empty_path_info, nil
|
||||||
|
set :strict_paths, true
|
||||||
|
|
||||||
set :app_file, nil
|
set :app_file, nil
|
||||||
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
|
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
|
||||||
|
|
|
@ -1499,4 +1499,20 @@ class RoutingTest < Minitest::Test
|
||||||
get '/foo/'
|
get '/foo/'
|
||||||
assert_equal 'Foo with a slash', body
|
assert_equal 'Foo with a slash', body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not treat routes with and without trailing slashes differently if :strict_paths is disabled' do
|
||||||
|
mock_app do
|
||||||
|
disable :strict_paths
|
||||||
|
|
||||||
|
get '/foo' do
|
||||||
|
'foo'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/foo'
|
||||||
|
assert_equal 'foo', body
|
||||||
|
|
||||||
|
get '/foo/'
|
||||||
|
assert_equal 'foo', body
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue