From ece96f658c631cae662d3849b35ee2723c368abe Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 27 Aug 2013 17:37:48 -0400 Subject: - Fix an obscure problem when combining a virtual root with a route with a ``*traverse`` in its pattern. Now the traversal path generated in such a configuration will be correct, instead of an element missing a leading slash. --- CHANGES.txt | 5 +++++ pyramid/tests/test_traversal.py | 17 +++++++++++++++++ pyramid/traversal.py | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1eeb0ce7b..0db274a19 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -149,6 +149,11 @@ Features Bug Fixes --------- +- Fix an obscure problem when combining a virtual root with a route with a + ``*traverse`` in its pattern. Now the traversal path generated in + such a configuration will be correct, instead of an element missing + a leading slash. + - Fixed a Mako renderer bug returning a tuple with a previous defname value in some circumstances. See https://github.com/Pylons/pyramid/issues/1037 for more information. diff --git a/pyramid/tests/test_traversal.py b/pyramid/tests/test_traversal.py index 2e45ae1a9..ba0be7e06 100644 --- a/pyramid/tests/test_traversal.py +++ b/pyramid/tests/test_traversal.py @@ -456,6 +456,23 @@ class ResourceTreeTraverserTests(unittest.TestCase): self.assertEqual(result['virtual_root'], resource) self.assertEqual(result['virtual_root_path'], ()) + def test_withroute_and_traverse_and_vroot(self): + abc = DummyContext() + resource = DummyContext(next=abc) + environ = self._getEnviron(HTTP_X_VHM_ROOT='/abc') + request = DummyRequest(environ) + traverser = self._makeOne(resource) + matchdict = {'traverse':text_('/foo/bar')} + request.matchdict = matchdict + result = traverser(request) + self.assertEqual(result['context'], abc) + self.assertEqual(result['view_name'], 'foo') + self.assertEqual(result['subpath'], ('bar',)) + self.assertEqual(result['traversed'], ('abc', 'foo')) + self.assertEqual(result['root'], resource) + self.assertEqual(result['virtual_root'], abc) + self.assertEqual(result['virtual_root_path'], ('abc',)) + class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): from pyramid.traversal import find_interface diff --git a/pyramid/traversal.py b/pyramid/traversal.py index ed49d8743..469e77454 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -640,7 +640,7 @@ class ResourceTreeTraverser(object): # this is a *traverse stararg (not a {traverse}) # routing has already decoded these elements, so we just # need to join them - path = slash.join(path) or slash + path = '/' + slash.join(path) or slash subpath = matchdict.get('subpath', ()) if not is_nonstr_iter(subpath): -- cgit v1.2.3