Skip to content

Commit 8cc211a

Browse files
committed
Relax route name restriction: add dashes
1 parent 3e68ce9 commit 8cc211a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGES
22
=======
33

4+
0.18.4 (13-11-2015)
5+
-------------------
6+
7+
- Relax rule for router names again by adding dash to allowed
8+
characters: they may contain identifiers, dashes, dots and columns
9+
10+
411
0.18.3 (25-10-2015)
512
-------------------
613

aiohttp/web_urldispatcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class UrlDispatcher(AbstractRouter, collections.abc.Mapping):
389389
r'^\{(?P<var>[a-zA-Z][_a-zA-Z0-9]*):(?P<re>.+)\}$')
390390
GOOD = r'[^{}/]+'
391391
ROUTE_RE = re.compile(r'(\{[_a-zA-Z][^{}]*(?:\{[^{}]*\}[^{}]*)*\})')
392-
NAME_SPLIT_RE = re.compile('[.:]')
392+
NAME_SPLIT_RE = re.compile('[.:-]')
393393

394394
METHODS = {hdrs.METH_ANY, hdrs.METH_POST,
395395
hdrs.METH_GET, hdrs.METH_PUT, hdrs.METH_DELETE,
@@ -449,10 +449,10 @@ def register_route(self, route):
449449
parts = self.NAME_SPLIT_RE.split(name)
450450
for part in parts:
451451
if not part.isidentifier() or keyword.iskeyword(part):
452-
raise ValueError('Incorrect route name value, '
453-
'Route name should be a sequence of '
452+
raise ValueError('Incorrect route name {!r}, '
453+
'the name should be a sequence of '
454454
'python identifiers separated '
455-
'by dot or column')
455+
'by dash, dot or column'.format(name))
456456
if name in self._routes:
457457
raise ValueError('Duplicate {!r}, '
458458
'already handled by {!r}'

tests/test_urldispatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_register_route_checks(self):
8383
route = PlainRoute('GET', handler, 'return', '/handler/to/path')
8484
self.assertRaises(ValueError, self.router.register_route, route)
8585

86-
route = PlainRoute('GET', handler, 'test.test:test',
86+
route = PlainRoute('GET', handler, 'test.test:test-test',
8787
'/handler/to/path')
8888
self.router.register_route(route)
8989

0 commit comments

Comments
 (0)