diff --git a/sanic/router.py b/sanic/router.py index 7ae28f09..621d3733 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -151,16 +151,11 @@ class Router: properties = {"unhashable": None} def add_parameter(match): - # We could receive NAME or NAME:PATTERN name = match.group(1) - pattern = 'string' - if ':' in name: - name, pattern = name.split(':', 1) + name, _type, pattern = self.parse_parameter_string(name) - default = (str, pattern) - # Pull from pre-configured types - _type, pattern = REGEX_TYPES.get(pattern, default) - parameter = Parameter(name=name, cast=_type) + parameter = Parameter( + name=name, cast=_type) parameters.append(parameter) # Mark the whole route as unhashable if it has the hash key in it diff --git a/tests/test_views.py b/tests/test_views.py index 456b714d..afa52d8b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -240,6 +240,7 @@ def test_composition_view_runs_methods_as_expected(): request, response = sanic_endpoint_test(app, uri='/', method=method) assert response.text == 'second method' + def test_composition_view_rejects_invalid_methods(): app = Sanic('test_composition_view')