Handle 0 as an integer argument (Fixes #212)
This commit is contained in:
@@ -862,8 +862,6 @@ class URLPattern():
|
||||
if arg is None:
|
||||
return
|
||||
if 'name' in segment:
|
||||
if not arg:
|
||||
return
|
||||
args[segment['name']] = arg
|
||||
if path is not None:
|
||||
return
|
||||
@@ -879,6 +877,8 @@ class URLPattern():
|
||||
|
||||
def _string_segment(self, value):
|
||||
s = value.split('/', 1)
|
||||
if len(s[0]) == 0:
|
||||
return None, None
|
||||
return s[0], s[1] if len(s) > 1 else None
|
||||
|
||||
def _int_segment(self, value):
|
||||
|
||||
@@ -26,10 +26,14 @@ class TestURLPattern(unittest.TestCase):
|
||||
p = URLPattern('/<arg>')
|
||||
self.assertEqual(p.match('/foo'), {'arg': 'foo'})
|
||||
self.assertIsNone(p.match('/'))
|
||||
self.assertIsNone(p.match('//'))
|
||||
self.assertIsNone(p.match(''))
|
||||
self.assertIsNone(p.match('foo/'))
|
||||
self.assertIsNone(p.match('/foo/'))
|
||||
self.assertIsNone(p.match('//foo/'))
|
||||
self.assertIsNone(p.match('/foo//'))
|
||||
self.assertIsNone(p.match('/foo/bar'))
|
||||
self.assertIsNone(p.match('/foo//bar'))
|
||||
|
||||
p = URLPattern('/<arg>/')
|
||||
self.assertEqual(p.match('/foo/'), {'arg': 'foo'})
|
||||
@@ -64,6 +68,8 @@ class TestURLPattern(unittest.TestCase):
|
||||
def test_int_argument(self):
|
||||
p = URLPattern('/users/<int:id>')
|
||||
self.assertEqual(p.match('/users/123'), {'id': 123})
|
||||
self.assertEqual(p.match('/users/-123'), {'id': -123})
|
||||
self.assertEqual(p.match('/users/0'), {'id': 0})
|
||||
self.assertIsNone(p.match('/users/'))
|
||||
self.assertIsNone(p.match('/users/abc'))
|
||||
self.assertIsNone(p.match('/users/123abc'))
|
||||
|
||||
Reference in New Issue
Block a user