summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/mapper.py17
-rw-r--r--tests/test_functional/test_utils.py6
2 files changed, 19 insertions, 4 deletions
diff --git a/routes/mapper.py b/routes/mapper.py
index bfcea4a..70e4930 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -594,7 +594,10 @@ class Mapper(SubMapperParent):
# Save the master regexp
regexp = '|'.join(['(?:%s)' % x for x in regexps])
self._master_reg = regexp
- self._master_regexp = re.compile(regexp)
+ try:
+ self._master_regexp = re.compile(regexp)
+ except OverflowError:
+ self._master_regexp = None
self._created_regs = True
def _match(self, url, environ):
@@ -631,9 +634,15 @@ class Mapper(SubMapperParent):
domain_match = self.domain_match
debug = self.debug
- # Check to see if its a valid url against the main regexp
- # Done for faster invalid URL elimination
- valid_url = re.match(self._master_regexp, url)
+ if self._master_regexp is not None:
+ # Check to see if its a valid url against the main regexp
+ # Done for faster invalid URL elimination
+ valid_url = re.match(self._master_regexp, url)
+ else:
+ # Regex is None due to OverflowError caused by too many routes.
+ # This will allow larger projects to work but might increase time
+ # spent invalidating URLs in the loop below.
+ valid_url = True
if not valid_url:
return (None, None, matchlog)
diff --git a/tests/test_functional/test_utils.py b/tests/test_functional/test_utils.py
index dfb1b90..e952baf 100644
--- a/tests/test_functional/test_utils.py
+++ b/tests/test_functional/test_utils.py
@@ -158,6 +158,12 @@ class TestUtils(unittest.TestCase):
eq_('/post/index/4', url.current(controller='post'))
eq_('http://www.example.com:8080/blog/view/4', url.current(qualified=True))
+ def test_route_overflow(self):
+ m = self.con.mapper
+ m.create_regs(["x"*50000])
+ m.connect('route-overflow', "x"*50000)
+ url = URLGenerator(m, {})
+ eq_("/%s" % ("x"*50000), url('route-overflow'))
def test_with_route_names(self):
m = self.con.mapper