Support negative numbers for int path components (Fixes #137)
This commit is contained in:
@@ -736,7 +736,7 @@ class URLPattern():
|
||||
if type_ == 'string':
|
||||
pattern = '[^/]+'
|
||||
elif type_ == 'int':
|
||||
pattern = '\\d+'
|
||||
pattern = '-?\\d+'
|
||||
elif type_ == 'path':
|
||||
pattern = '.+'
|
||||
elif type_.startswith('re:'):
|
||||
|
||||
@@ -56,10 +56,12 @@ class TestURLPattern(unittest.TestCase):
|
||||
|
||||
p = URLPattern('/users/<int:id>/<int:id2>/')
|
||||
self.assertEqual(p.match('/users/123/456/'), {'id': 123, 'id2': 456})
|
||||
self.assertEqual(p.match('/users/123/-456/'), {'id': 123, 'id2': -456})
|
||||
self.assertIsNone(p.match('/users/'))
|
||||
self.assertIsNone(p.match('/users/123/456'))
|
||||
self.assertIsNone(p.match('/users/123/-456'))
|
||||
self.assertIsNone(p.match('/users/123/abc/'))
|
||||
self.assertIsNone(p.match('/users/123/456/abc'))
|
||||
self.assertIsNone(p.match('/users/123/-456/abc'))
|
||||
self.assertIsNone(p.match('/users/--123/456/'))
|
||||
|
||||
def test_path_argument(self):
|
||||
p = URLPattern('/users/<path:path>')
|
||||
|
||||
Reference in New Issue
Block a user