summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-03-22 01:05:14 -0400
committerChris McDonough <chrism@plope.com>2011-03-22 01:05:14 -0400
commitb596e1812627c359908759d7a8d83c339f08e385 (patch)
tree2f86ce9155d1c9c1944ad4dfd301d377852e0e6f
parentca1922611cb7558030d9abff1c16e3ffbde9e0dd (diff)
downloadpyramid-b596e1812627c359908759d7a8d83c339f08e385.tar.gz
pyramid-b596e1812627c359908759d7a8d83c339f08e385.tar.bz2
pyramid-b596e1812627c359908759d7a8d83c339f08e385.zip
- Include SCRIPT_NAME in redirects issued by
``pyramid.view.append_slash_notfound_view`` (see https://github.com/Pylons/pyramid/issues#issue/149). Closes #149
-rw-r--r--CHANGES.txt4
-rw-r--r--pyramid/tests/test_view.py9
-rw-r--r--pyramid/view.py7
3 files changed, 17 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e9abd5b55..9ce6184a3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -36,6 +36,10 @@ Bug Fixes
``pyramid.url.route_url`` or ``pyramid.url.resource_url`` (see
https://github.com/Pylons/pyramid/issues#issue/141).
+- Include SCRIPT_NAME in redirects issued by
+ ``pyramid.view.append_slash_notfound_view`` (see
+ https://github.com/Pylons/pyramid/issues#issue/149).
+
1.0 (2011-01-30)
================
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py
index 43b9e2766..c7d90a2af 100644
--- a/pyramid/tests/test_view.py
+++ b/pyramid/tests/test_view.py
@@ -24,6 +24,7 @@ class BaseTest(object):
'SERVER_NAME':'localhost',
'SERVER_PORT':'8080',
'REQUEST_METHOD':'GET',
+ 'PATH_INFO':'/',
}
environ.update(extras)
return environ
@@ -406,6 +407,14 @@ class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
self.assertEqual(response.status, '302 Found')
self.assertEqual(response.location, '/abc/')
+ def test_matches_with_script_name(self):
+ request = self._makeRequest(PATH_INFO='/abc', SCRIPT_NAME='/foo')
+ context = ExceptionResponse()
+ self._registerMapper(request.registry, True)
+ response = self._callFUT(context, request)
+ self.assertEqual(response.status, '302 Found')
+ self.assertEqual(response.location, '/foo/abc/')
+
def test_with_query_string(self):
request = self._makeRequest(PATH_INFO='/abc', QUERY_STRING='a=1&b=2')
context = ExceptionResponse()
diff --git a/pyramid/view.py b/pyramid/view.py
index c14a587ea..659a63e1e 100644
--- a/pyramid/view.py
+++ b/pyramid/view.py
@@ -291,15 +291,16 @@ class AppendSlashNotFoundViewFactory(object):
# backwards compat for an append_notslash_view registered via
# config.set_notfound_view instead of as a proper exception view
context = request.exception
- path = request.environ.get('PATH_INFO', '/')
+ path = request.path
registry = request.registry
mapper = registry.queryUtility(IRoutesMapper)
if mapper is not None and not path.endswith('/'):
slashpath = path + '/'
for route in mapper.get_routes():
if route.match(slashpath) is not None:
- if request.environ.get('QUERY_STRING'):
- slashpath += '?' + request.environ['QUERY_STRING']
+ qs = request.query_string
+ if qs:
+ slashpath += '?' + qs
return HTTPFound(location=slashpath)
return self.notfound_view(context, request)