Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from djay/master

Support for query strings in plone.app.redirector. Closes https://dev.plone.org/ticket/12354 and https://dev.plone.org/ticket/9967.
  • Loading branch information...
commit 67859bf3637ee1ceea2da2fe346a98853045d778 2 parents 250436c + f412466
Laurence Rowe lrowe authored
2  .gitignore
View
@@ -0,0 +1,2 @@
+*.pyc
+*.egg-info
6 CHANGES.txt
View
@@ -7,6 +7,12 @@ Changelog
- Support parts of views e.g. mypage/@@myview/somepart
[anthonygerrard]
+- #12354 will redirect based on the query string as well as path if query_string
+ stored. [djay]
+
+- #9967 will append the same query string after redirecting to be more tracker
+ friendly. [djay]
+
1.1.2 - 2011-07-05
------------------
19 plone/app/redirector/browser.py
View
@@ -38,7 +38,20 @@ def attempt_redirect(self):
return False
old_path = '/'.join(old_path_elements)
- new_path = storage.get(old_path)
+
+ # First lets try with query string in cases or content migration
+
+ new_path = None
+
+ query_string = self.request.QUERY_STRING
+ if query_string:
+ new_path = storage.get("%s?%s" % (old_path,query_string))
+ # if we matched on the query_string we don't want to include it in redirect
+ if new_path:
+ query_string = ''
+
+ if not new_path:
+ new_path = storage.get(old_path)
if not new_path:
new_path = self.find_redirect_if_view(old_path_elements, storage)
@@ -50,6 +63,10 @@ def attempt_redirect(self):
return False
url = self.request.physicalPathToURL(new_path)
+
+ # some analytics programs might use this info to track
+ if query_string:
+ url += "?"+query_string
self.request.response.redirect(url, status=301, lock=1)
return True
21 plone/app/redirector/tests/test_view.py
View
@@ -15,9 +15,10 @@ def afterSetUp(self):
self.folder = self.portal.testfolder
self.storage = getUtility(IRedirectionStorage)
- def view(self, context, actual_url):
+ def view(self, context, actual_url, query_string=''):
request = self.app.REQUEST
request['ACTUAL_URL'] = actual_url
+ request['QUERY_STRING'] = query_string
return getMultiAdapter((context, request), name='plone_redirector_view')
def test_attempt_redirect_with_known_url(self):
@@ -63,6 +64,24 @@ def test_attempt_redirect_with_quoted_url(self):
self.assertEquals(301, self.app.REQUEST.response.getStatus())
self.assertEquals(fu + '/bar/baz%20quux', self.app.REQUEST.response.getHeader('location'))
+ def test_attempt_redirect_with_query_string(self):
+ fp = '/'.join(self.folder.getPhysicalPath())
+ fu = self.folder.absolute_url()
+ self.storage.add(fp + '/foo?blah=blah', fp + '/bar')
+ view = self.view(self.portal, fu + '/foo','blah=blah')
+ self.assertEquals(True, view.attempt_redirect())
+ self.assertEquals(301, self.app.REQUEST.response.getStatus())
+ self.assertEquals(fu + '/bar', self.app.REQUEST.response.getHeader('location'))
+
+ def test_attempt_redirect_appending_query_string(self):
+ fp = '/'.join(self.folder.getPhysicalPath())
+ fu = self.folder.absolute_url()
+ self.storage.add(fp + '/foo', fp + '/bar')
+ view = self.view(self.portal, fu + '/foo', 'blah=blah')
+ self.assertEquals(True, view.attempt_redirect())
+ self.assertEquals(301, self.app.REQUEST.response.getStatus())
+ self.assertEquals(fu + '/bar?blah=blah', self.app.REQUEST.response.getHeader('location'))
+
def test_find_first_parent_found_leaf(self):
self.folder.invokeFactory('Folder', 'f1')
fu = self.folder.absolute_url()
Please sign in to comment.
Something went wrong with that request. Please try again.