Permalink
Browse files

Merge pull request #634 from 2nd/fix.urldispatch-629

Replacement markers of url dispatcher can contain regex with colons.
  • Loading branch information...
2 parents e491890 + 88bbd46 commit 3fce167f6378cf8eabafdcc3f6c7fa2f7225c9e2 @mmerickel mmerickel committed Jul 10, 2012
Showing with 11 additions and 1 deletion.
  1. +8 −0 pyramid/tests/test_urldispatch.py
  2. +3 −1 pyramid/urldispatch.py
@@ -311,6 +311,14 @@ def test_custom_regex(self):
self.assertEqual(matcher('foo/baz/biz/buz/bar'), None)
self.assertEqual(generator({'baz':1, 'buz':2, 'bar': 'html'}),
'/foo/1/biz/2.html')
+
+ def test_custom_regex_with_colons(self):
+ matcher, generator = self._callFUT('foo/{baz}/biz/{buz:(?:[^/\.]+)}.{bar}')
+ self.assertEqual(matcher('/foo/baz/biz/buz.bar'),
+ {'baz':'baz', 'buz':'buz', 'bar':'bar'})
+ self.assertEqual(matcher('foo/baz/biz/buz/bar'), None)
+ self.assertEqual(generator({'baz':1, 'buz':2, 'bar': 'html'}),
+ '/foo/1/biz/2.html')
def test_mixed_newstyle_oldstyle_pattern_defaults_to_newstyle(self):
# pattern: '\\/foo\\/(?P<baz>abc)\\/biz\\/(?P<buz>[^/]+)\\/bar$'
View
@@ -148,7 +148,9 @@ def _compile_route(route):
name = pat.pop() # unicode
name = name[1:-1]
if ':' in name:
- name, reg = name.split(':')
+ # reg may contain colons as well,
+ # so we must strictly split name into two parts
+ name, reg = name.split(':', 1)
else:
reg = '[^/]+'
gen.append('%%(%s)s' % native_(name)) # native

0 comments on commit 3fce167

Please sign in to comment.