diff options
author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-11 14:30:53 +0000 |
---|---|---|
committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-11 14:30:53 +0000 |
commit | 0b4122d1387e3c793661c0828278a021364691d4 (patch) | |
tree | e4d5dbce18cac7029a4d3762bd57e25d0b1e8280 | |
parent | 75d29fa448a8b99f7ca1b4859f20fb57ea15f695 (diff) | |
download | django-0b4122d1387e3c793661c0828278a021364691d4.tar.gz |
unicode: Fixed the urlencode filter to work with non-ASCII strings. Fixed a
similar error in HttpRedirect processing.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r-- | django/http/__init__.py | 8 | ||||
-rw-r--r-- | django/template/defaultfilters.py | 4 | ||||
-rw-r--r-- | tests/regressiontests/defaultfilters/tests.py | 8 |
3 files changed, 10 insertions, 10 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py index 5735300159..be48acdc41 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -1,9 +1,9 @@ import os from Cookie import SimpleCookie from pprint import pformat -from urllib import urlencode, quote +from urllib import urlencode from django.utils.datastructures import MultiValueDict -from django.utils.encoding import smart_str +from django.utils.encoding import smart_str, iri_to_uri RESERVED_CHARS="!*'();:@&=+$,/?%#[]" @@ -334,14 +334,14 @@ class HttpResponseRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) - self['Location'] = quote(redirect_to, safe=RESERVED_CHARS) + self['Location'] = iri_to_uri(redirect_to) class HttpResponsePermanentRedirect(HttpResponse): status_code = 301 def __init__(self, redirect_to): HttpResponse.__init__(self) - self['Location'] = quote(redirect_to, safe=RESERVED_CHARS) + self['Location'] = iri_to_uri(redirect_to) class HttpResponseNotModified(HttpResponse): status_code = 304 diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 27a0b07df0..d31f351670 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -175,8 +175,8 @@ upper = stringfilter(upper) def urlencode(value): "Escapes a value for use in a URL" - import urllib - return force_unicode(urllib.quote(value)) + from django.utils.http import urlquote + return urlquote(value) urlencode = stringfilter(urlencode) def urlize(value): diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index d2335dd87b..1acad6135c 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -111,14 +111,14 @@ u'MIXED CASE INPUT' u'\xcb' ->>> urlencode(u'jack & jill') -u'jack%20%26%20jill' +>>> urlencode(u'fran\xe7ois & jill') +u'fran%C3%A7ois%20%26%20jill' >>> urlencode(1) u'1' >>> iriencode(u'S\xf8r-Tr\xf8ndelag') u'S%C3%B8r-Tr%C3%B8ndelag' ->>> iriencode(urlencode(u'jack & jill')) -u'jack%20%26%20jill' +>>> iriencode(urlencode(u'fran\xe7ois & jill')) +u'fran%C3%A7ois%20%26%20jill' >>> urlizetrunc(u'http://short.com/', 20) u'<a href="http://short.com/" rel="nofollow">http://short.com/</a>' |