check if method is added in strict slash logic
This commit is contained in:
parent
01042c1d98
commit
bb8e9c6438
|
@ -130,8 +130,15 @@ class Router:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Add versions with and without trailing /
|
# 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 = (
|
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 = (
|
without_slash_is_missing = (
|
||||||
uri[-1] == '/' and not
|
uri[-1] == '/' and not
|
||||||
|
|
|
@ -44,6 +44,24 @@ def test_shorthand_routes_get():
|
||||||
request, response = app.test_client.post('/get')
|
request, response = app.test_client.post('/get')
|
||||||
assert response.status == 405
|
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():
|
def test_route_strict_slash():
|
||||||
app = Sanic('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
|
assert response.status == 200
|
||||||
|
|
||||||
app.remove_route('/test', clean_cache=True)
|
app.remove_route('/test', clean_cache=True)
|
||||||
|
app.remove_route('/test/', clean_cache=True)
|
||||||
|
|
||||||
request, response = app.test_client.get('/test')
|
request, response = app.test_client.get('/test')
|
||||||
assert response.status == 404
|
assert response.status == 404
|
||||||
|
|
Loading…
Reference in New Issue
Block a user