summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2012-07-10 11:09:39 -0700
committerMichael Merickel <michael@merickel.org>2012-07-10 11:09:39 -0700
commit3fce167f6378cf8eabafdcc3f6c7fa2f7225c9e2 (patch)
treed73179f56db8dd9ca31a75e8cfbe8d410409300c
parente4918905845870bde25c07625b895074f66de790 (diff)
parent88bbd46c9a5fab52548f26fe4655a89c00332ad5 (diff)
downloadpyramid-3fce167f6378cf8eabafdcc3f6c7fa2f7225c9e2.tar.gz
pyramid-3fce167f6378cf8eabafdcc3f6c7fa2f7225c9e2.tar.bz2
pyramid-3fce167f6378cf8eabafdcc3f6c7fa2f7225c9e2.zip
Merge pull request #634 from 2nd/fix.urldispatch-629
Replacement markers of url dispatcher can contain regex with colons.
-rw-r--r--pyramid/tests/test_urldispatch.py8
-rw-r--r--pyramid/urldispatch.py4
2 files changed, 11 insertions, 1 deletions
diff --git a/pyramid/tests/test_urldispatch.py b/pyramid/tests/test_urldispatch.py
index e15242f75..b2164717e 100644
--- a/pyramid/tests/test_urldispatch.py
+++ b/pyramid/tests/test_urldispatch.py
@@ -311,6 +311,14 @@ class TestCompileRoute(unittest.TestCase):
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$'
diff --git a/pyramid/urldispatch.py b/pyramid/urldispatch.py
index cccff14ba..4182ea665 100644
--- a/pyramid/urldispatch.py
+++ b/pyramid/urldispatch.py
@@ -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