1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Add tests for trailing slashes in the path

Related to #1107

The router treats paths with trailing slashes different from the ones
without. Add tests for this and also mention it in the README.
Following @zzak's
[comment](https://github.com/sinatra/sinatra/issues/1107#issuecomment-217849114).
This commit is contained in:
Tejas Bubane 2016-05-09 19:37:14 +05:30
parent 1e75f50aa5
commit af7284fbf9
2 changed files with 27 additions and 0 deletions

View file

@ -160,6 +160,14 @@ end
Routes are matched in the order they are defined. The first route that
matches the request is invoked.
Routes with trailing slashes are different from the ones without:
```ruby
get '/foo' do
# Does not match "GET /foo/"
end
```
Route patterns may include named parameters, accessible via the
`params` hash:

View file

@ -1452,4 +1452,23 @@ class RoutingTest < Minitest::Test
end
get '/users/1/status'
end
it 'treats routes with and without trailing slashes differently' do
mock_app do
get '/foo' do
'Foo'
end
get '/foo/' do
'Foo with a slash'
end
end
get '/foo'
assert_equal 'Foo', body
refute_equal 'Foo with a slash', body
get '/foo/'
assert_equal 'Foo with a slash', body
end
end