Skip to content

Commit 947c1a2

Browse files
committed
Fix issue #264 with error during constructing of url with regex parts
1 parent ee35cfe commit 947c1a2

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.14.3
2+
current_version = 0.14.4
33
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+\d+))?
44
serialize =
55
{major}.{minor}.{patch}{release}

CHANGES.txt

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

4+
0.14.4 (01-29-2015)
5+
-------------------
6+
7+
- Fix issue with error during constructing of url with regex parts #264
8+
49
0.14.3 (01-28-2015)
510
-------------------
611

aiohttp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This relies on each of the submodules having an __all__ variable.
22

3-
__version__ = '0.14.3'
3+
__version__ = '0.14.4'
44

55

66
from . import hdrs # noqa

aiohttp/web.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ def add_route(self, method, path, handler, *, name=None):
14011401
assert method in self.METHODS, method
14021402
parts = []
14031403
factory = PlainRoute
1404+
format_parts = []
14041405
for part in path.split('/'):
14051406
if not part:
14061407
continue
@@ -1409,16 +1410,19 @@ def add_route(self, method, path, handler, *, name=None):
14091410
parts.append('(?P<' + match.group('var') + '>' +
14101411
self.GOOD + ')')
14111412
factory = DynamicRoute
1413+
format_parts.append('{'+match.group('var')+'}')
14121414
continue
14131415

14141416
match = self.DYN_WITH_RE.match(part)
14151417
if match:
14161418
parts.append('(?P<' + match.group('var') + '>' +
14171419
match.group('re') + ')')
14181420
factory = DynamicRoute
1421+
format_parts.append('{'+match.group('var')+'}')
14191422
continue
14201423
if self.PLAIN.match(part):
14211424
parts.append(re.escape(part))
1425+
format_parts.append(part)
14221426
continue
14231427
raise ValueError("Invalid path '{}'['{}']".format(path, part))
14241428
if factory is PlainRoute:
@@ -1432,7 +1436,8 @@ def add_route(self, method, path, handler, *, name=None):
14321436
except re.error as exc:
14331437
raise ValueError(
14341438
"Bad pattern '{}': {}".format(pattern, exc)) from None
1435-
route = DynamicRoute(method, handler, name, compiled, path)
1439+
formatter = '/' + '/'.join(format_parts)
1440+
route = DynamicRoute(method, handler, name, compiled, formatter)
14361441
self._register_endpoint(route)
14371442
return route
14381443

tests/test_urldispatch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,11 @@ def test_add_route_with_invalid_re(self):
326326
"Bad pattern '/handler/(?P<to>+++)': nothing to repeat",
327327
str(ctx.exception))
328328
self.assertIsNone(ctx.exception.__cause__)
329+
330+
def test_route_dynamic_with_regex_spec(self):
331+
handler = self.make_handler()
332+
route = self.router.add_route('GET', '/get/{num:^\d+}', handler,
333+
name='name')
334+
335+
url = route.url(parts={'num': '123'})
336+
self.assertEqual('/get/123', url)

0 commit comments

Comments
 (0)