Merge lp:~cmiller/django-openid-auth/encode-redirected-uris-better into lp:~django-openid-auth/django-openid-auth/trunk

Proposed by Chad Miller
Status: Merged
Merged at revision: 93
Proposed branch: lp:~cmiller/django-openid-auth/encode-redirected-uris-better
Merge into: lp:~django-openid-auth/django-openid-auth/trunk
Diff against target: 15 lines (+5/-1)
1 file modified
django_openid_auth/views.py (+5/-1)
To merge this branch: bzr merge lp:~cmiller/django-openid-auth/encode-redirected-uris-better
Reviewer Review Type Date Requested Status
Facundo Batista (community) Approve
django-openid-auth developers Pending
Review via email: mp+108035@code.launchpad.net

Commit message

LP#936153, After login, redirecting to a URL that contains non-ASCII characters would fail because the naive "str(foo)" scheme used in urllib would use the default system encoding, which we can't trust at all.

To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote :

Encoding to UTF8 will give you a sequence of bytes with two or more values > 127 for each unicode character, and urllib.urlencode will transform those into encoded values, like:

>>> urllib.urlencode(dict(foo=u"moño".encode("utf8")))
'foo=mo%C3%B1o'

This is something that I saw a lot, so I think it's ok, but I'm no expert in URLs.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_openid_auth/views.py'
2--- django_openid_auth/views.py 2011-08-23 18:50:29 +0000
3+++ django_openid_auth/views.py 2012-05-30 18:31:29 +0000
4@@ -244,7 +244,11 @@
5 return_to += '&'
6 else:
7 return_to += '?'
8- return_to += urllib.urlencode({redirect_field_name: redirect_to})
9+ # Django gives us Unicode, which is great. We must encode URI. urllib
10+ # dumbly enforces str. We can't trust anything about the default
11+ # encoding inside str(foo) , so we must explicitly make foo a str.
12+ return_to += urllib.urlencode(
13+ {redirect_field_name: redirect_to.encode("UTF-8")})
14
15 return render_openid_request(request, openid_request, return_to)
16

Subscribers

People subscribed via source and target branches