diff options
author | Ben Bangert <ben@groovie.org> | 2009-11-20 09:07:22 -0800 |
---|---|---|
committer | Ben Bangert <ben@groovie.org> | 2009-11-20 09:07:22 -0800 |
commit | b0bd2d8f97720be5ec183a136297fbd2f0619ee7 (patch) | |
tree | 31a4440564fdc6c2e4aa1146773dc529ca7e7096 /routes | |
parent | 0d509b70abec053bf7b960d192d69a5c8990e2aa (diff) | |
download | routes-b0bd2d8f97720be5ec183a136297fbd2f0619ee7.tar.gz |
Fix bug with capturing large groups
--HG--
branch : trunk
Diffstat (limited to 'routes')
-rw-r--r-- | routes/mapper.py | 4 | ||||
-rw-r--r-- | routes/route.py | 22 |
2 files changed, 12 insertions, 14 deletions
diff --git a/routes/mapper.py b/routes/mapper.py index a0c7092..9778242 100644 --- a/routes/mapper.py +++ b/routes/mapper.py @@ -378,9 +378,7 @@ class Mapper(object): self._regprefix = re.compile(self.prefix + '(.*)') # Save the master regexp - regexp = '|'.join( - ['(?P<%s>%s)' % ('a' * (num + 1), x) for num, x in enumerate(regexps)] - ) + regexp = '|'.join(['(?:%s)' % x for x in regexps]) self._master_reg = regexp self._master_regexp = re.compile(regexp) self._created_regs = True diff --git a/routes/route.py b/routes/route.py index 1995781..1a70aac 100644 --- a/routes/route.py +++ b/routes/route.py @@ -282,7 +282,7 @@ class Route(object): reg = self.buildnextreg(self.routelist, clist, include_names)[0] if not reg: reg = '/' - reg = reg + '(/)?' + '$' + reg = reg + '/?' + '$' if not reg.startswith('/'): reg = '/' + reg @@ -313,7 +313,7 @@ class Route(object): if include_names: regparts.append('(?P<%s>%s)' % (var, partmatch)) else: - regparts.append('(%s)' % partmatch) + regparts.append('(?:%s)' % partmatch) else: regparts.append(re.escape(part)) regexp = ''.join(regparts) + '$' @@ -350,23 +350,23 @@ class Route(object): if include_names: partreg = '(?P<%s>%s)' % (var, self.reqs[var]) else: - partreg = '(%s)' % self.reqs[var] + partreg = '(?:%s)' % self.reqs[var] elif var == 'controller': if include_names: partreg = '(?P<%s>%s)' % (var, '|'.join(map(re.escape, clist))) else: - partreg = '(%s)' % '|'.join(map(re.escape, clist)) + partreg = '(?:%s)' % '|'.join(map(re.escape, clist)) elif self.prior in ['/', '#']: if include_names: partreg = '(?P<' + var + '>[^' + self.prior + ']+?)' else: - partreg = '([^' + self.prior + ']+?)' + partreg = '(?:[^' + self.prior + ']+?)' else: if not rest: if include_names: partreg = '(?P<%s>[^%s]+?)' % (var, '/') else: - partreg = '([^%s]+?)' % '/' + partreg = '(?:[^%s]+?)' % '/' else: end = ''.join(self.done_chars) rem = rest @@ -380,7 +380,7 @@ class Route(object): if include_names: partreg = '(?P<%s>[^%s]+?)' % (var, ''.join(rem)) else: - partreg = '([^%s]+?)' % ''.join(rem) + partreg = '(?:[^%s]+?)' % ''.join(rem) if self.reqs.has_key(var): noreqs = False @@ -441,7 +441,7 @@ class Route(object): if include_names: reg = '(?P<%s>.*)' % var + rest else: - reg = '(.*)' + rest + reg = '(?:.*)' + rest if not self.defaults.has_key(var): allblank = False noreqs = False @@ -450,17 +450,17 @@ class Route(object): if include_names: reg = '(?P<%s>.*)' % var + rest else: - reg = '(.*)' + rest + reg = '(?:.*)' + rest elif self.defaults.has_key(var): if include_names: reg = '(?P<%s>.*)' % var + rest else: - reg = '(.*)' + rest + reg = '(?:.*)' + rest else: if include_names: reg = '(?P<%s>.*)' % var + rest else: - reg = '(.*)' + rest + reg = '(?:.*)' + rest allblank = False noreqs = False elif part and part[-1] in self.done_chars: |