Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from zopefoundation/automatic-location-encoding
Browse files Browse the repository at this point in the history
encode unicode redirect URLs automatically
  • Loading branch information
Jim Fulton committed Nov 21, 2014
2 parents 0ee995b + 57fc685 commit 594ab05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bobo/README.txt
Expand Up @@ -22,6 +22,8 @@ To learn more. visit: http://bobo.digicool.com
Change History
==============

- Bobo will encode Unicode URLs for redirects automatically.

- Bobo will pass resource function arguments from data in JSON request bodies.

2.1.1 2014-07-06
Expand Down
2 changes: 2 additions & 0 deletions bobo/src/bobo.py
Expand Up @@ -345,6 +345,8 @@ def redirect(url, status=302, body=None,
"""
if body is None:
body = u'See %s' % url
if isinstance(url, unicode):
url = url.encode('utf-8')
response = webob.Response(status=status, headerlist=[('Location', url)])
response.content_type = content_type
response.unicode_body = body
Expand Down
8 changes: 8 additions & 0 deletions bobodoctestumentation/src/bobodoctestumentation/main.test
Expand Up @@ -336,3 +336,11 @@ Ordering
>>> app = makeapp(bobo_resources='bobo.testmodule1')
>>> app.get('/o').text
'f3'


Automatic encoding of redirect destinations
-------------------------------------------

>>> response = bobo.redirect(u"http://www.\u0113xample.com/")
>>> response.headers["location"]
'http://www.\xc4\x93xample.com/'
8 changes: 8 additions & 0 deletions bobodoctestumentation/src/bobodoctestumentation/more.txt
Expand Up @@ -1087,3 +1087,11 @@ with an Allow header.
>>> app.request('/users/54321',
... method="OPTIONS", status=405).headers["Allow"]
'GET, HEAD, POST, PUT'


Automatic encoding of redirect destinations
-------------------------------------------

Since URLs are often computed based on request data, it's easy for
applications to generate Unicode URLs. For this reason, unicode URL's
passed to ``bobo.redirect`` are UTF-8 encoded.

0 comments on commit 594ab05

Please sign in to comment.