diff options
author | Iuri de Silvio <iurisilvio@gmail.com> | 2011-12-09 15:31:06 -0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2011-12-14 19:47:29 +0100 |
commit | e9d77d70fe5c2de3ebedc014f6887e5d6213d549 (patch) | |
tree | d29c184a671795e61192cae9715b6200497371f8 | |
parent | b2f826a8da3759fda076da5d25680e873c937af0 (diff) | |
download | bottle-e9d77d70fe5c2de3ebedc014f6887e5d6213d549.tar.gz |
Solving float_filter bug and testing it.
-rwxr-xr-x | bottle.py | 4 | ||||
-rwxr-xr-x | test/test_router.py | 9 |
2 files changed, 11 insertions, 2 deletions
@@ -289,7 +289,7 @@ class Router(object): #: If true, static routes are no longer checked first. self.strict_order = strict self.filters = {'re': self.re_filter, 'int': self.int_filter, - 'float': self.re_filter, 'path': self.path_filter} + 'float': self.float_filter, 'path': self.path_filter} def re_filter(self, conf): return conf or self.default_pattern, None, None @@ -298,7 +298,7 @@ class Router(object): return r'-?\d+', int, lambda x: str(int(x)) def float_filter(self, conf): - return r'-?\d*\.\d+', float, lambda x: str(float(x)) + return r'-?[\d.]+', float, lambda x: str(float(x)) def path_filter(self, conf): return r'.*?', None, None diff --git a/test/test_router.py b/test/test_router.py index f7b884b..83096ca 100755 --- a/test/test_router.py +++ b/test/test_router.py @@ -57,6 +57,15 @@ class TestRouter(unittest.TestCase): self.assertMatches('/object/<id:int>', '/object/567', id=567) self.assertRaises(bottle.HTTPError, self.match, '/object/abc') + def testFloatFilter(self): + self.assertMatches('/object/<id:float>', '/object/1', id=1) + self.assertMatches('/object/<id:float>', '/object/1.1', id=1.1) + self.assertMatches('/object/<id:float>', '/object/.1', id=0.1) + self.assertMatches('/object/<id:float>', '/object/1.', id=1) + self.assertRaises(bottle.HTTPError, self.match, '/object/abc') + self.assertRaises(bottle.HTTPError, self.match, '/object/') + self.assertRaises(bottle.HTTPError, self.match, '/object/.') + def testWildcardNames(self): self.assertMatches('/alpha/:abc', '/alpha/alpha', abc='alpha') self.assertMatches('/alnum/:md5', '/alnum/sha1', md5='sha1') |