Skip to content

Commit a0dd7c8

Browse files
Support negative numbers for int path components (Fixes #137)
1 parent a80841f commit a0dd7c8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/microdot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def __init__(self, url_pattern):
736736
if type_ == 'string':
737737
pattern = '[^/]+'
738738
elif type_ == 'int':
739-
pattern = '\\d+'
739+
pattern = '-?\\d+'
740740
elif type_ == 'path':
741741
pattern = '.+'
742742
elif type_.startswith('re:'):

tests/test_url_pattern.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ def test_int_argument(self):
5656

5757
p = URLPattern('/users/<int:id>/<int:id2>/')
5858
self.assertEqual(p.match('/users/123/456/'), {'id': 123, 'id2': 456})
59+
self.assertEqual(p.match('/users/123/-456/'), {'id': 123, 'id2': -456})
5960
self.assertIsNone(p.match('/users/'))
60-
self.assertIsNone(p.match('/users/123/456'))
61+
self.assertIsNone(p.match('/users/123/-456'))
6162
self.assertIsNone(p.match('/users/123/abc/'))
62-
self.assertIsNone(p.match('/users/123/456/abc'))
63+
self.assertIsNone(p.match('/users/123/-456/abc'))
64+
self.assertIsNone(p.match('/users/--123/456/'))
6365

6466
def test_path_argument(self):
6567
p = URLPattern('/users/<path:path>')

0 commit comments

Comments
 (0)