Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add :strict_paths option for managing trailing slashes #1273

Merged
merged 1 commit into from
Apr 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ def route_eval
def process_route(pattern, conditions, block = nil, values = [])
route = @request.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)

params.delete("ignore") # TODO: better params handling, maybe turn it into "smart" object or detect changes
Expand Down Expand Up @@ -1845,6 +1846,7 @@ class << self
set :absolute_redirects, true
set :prefixed_redirects, false
set :empty_path_info, nil
set :strict_paths, true

set :app_file, nil
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
Expand Down
16 changes: 16 additions & 0 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1499,4 +1499,20 @@ def authorize(username, password)
get '/foo/'
assert_equal 'Foo with a slash', body
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