diff --git a/sanic/router.py b/sanic/router.py index 21c98766..b601622c 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -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 diff --git a/tests/test_routes.py b/tests/test_routes.py index b4ed7cf3..b6b62283 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -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') @@ -431,7 +449,7 @@ def test_websocket_route_with_subprotocols(): 'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==', 'Sec-WebSocket-Version': '13'}) assert response.status == 101 - + assert results == ['bar', 'bar', None, None] @@ -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