Merge pull request #1006 from r0fls/routing-fix
check if method is added in strict slash logic
This commit is contained in:
commit
bf6ed217c2
|
@ -130,8 +130,15 @@ class Router:
|
|||
return
|
||||
|
||||
# Add versions with and without trailing /
|
||||
slashed_methods = self.routes_all.get(uri + '/', frozenset({}))
|
||||
if isinstance(methods, Iterable):
|
||||
_slash_is_missing = all(method in slashed_methods for
|
||||
method in methods)
|
||||
else:
|
||||
_slash_is_missing = methods in slashed_methods
|
||||
|
||||
slash_is_missing = (
|
||||
not uri[-1] == '/' and not self.routes_all.get(uri + '/', False)
|
||||
not uri[-1] == '/' and not _slash_is_missing
|
||||
)
|
||||
without_slash_is_missing = (
|
||||
uri[-1] == '/' and not
|
||||
|
|
|
@ -44,6 +44,24 @@ def test_shorthand_routes_get():
|
|||
request, response = app.test_client.post('/get')
|
||||
assert response.status == 405
|
||||
|
||||
def test_shorthand_routes_multiple():
|
||||
app = Sanic('test_shorthand_routes_multiple')
|
||||
|
||||
@app.get('/get')
|
||||
def get_handler(request):
|
||||
return text('OK')
|
||||
|
||||
@app.options('/get')
|
||||
def options_handler(request):
|
||||
return text('')
|
||||
|
||||
request, response = app.test_client.get('/get/')
|
||||
assert response.status == 200
|
||||
assert response.text == 'OK'
|
||||
|
||||
request, response = app.test_client.options('/get/')
|
||||
assert response.status == 200
|
||||
|
||||
def test_route_strict_slash():
|
||||
app = Sanic('test_route_strict_slash')
|
||||
|
||||
|
@ -754,6 +772,7 @@ def test_remove_route_without_clean_cache():
|
|||
assert response.status == 200
|
||||
|
||||
app.remove_route('/test', clean_cache=True)
|
||||
app.remove_route('/test/', clean_cache=True)
|
||||
|
||||
request, response = app.test_client.get('/test')
|
||||
assert response.status == 404
|
||||
|
|
Loading…
Reference in New Issue
Block a user