Protect urlencode calls against Unicode data

These would cause page errors if passed anything not in the ASCII
character set. This change allows for packages to have names composed of
any Unicode characters, not just those in the ASCII set.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2012-02-12 21:54:05 -06:00
parent c3ebf7deae
commit 30acd5c816
3 changed files with 7 additions and 4 deletions

View File

@ -9,8 +9,11 @@
register = template.Library()
def link_encode(url, query, doseq=False):
data = urlencode(query, doseq).replace('&', '&amp;')
def link_encode(url, query):
# massage the data into all utf-8 encoded strings first, so urlencode
# doesn't barf at the data we pass it
query = dict((k, unicode(v).encode('utf-8')) for k, v in query.items())
data = urlencode(query).replace('&', '&amp;')
return "%s?%s" % (url, data)
@register.filter

View File

@ -28,7 +28,7 @@
(r'^stale_relations/$', 'stale_relations'),
(r'^stale_relations/update/$','stale_relations_update'),
(r'^(?P<name>[A-z0-9\-+.]+)/$',
(r'^(?P<name>[^ /]+)/$',
'details'),
(r'^(?P<repo>[A-z0-9\-]+)/(?P<name>[^ /]+)/$',
'details'),

View File

@ -142,7 +142,7 @@ def details(request, name='', repo='', arch=''):
('q', name),
]
# only include non-blank values in the query we generate
pkg_data = [(x, y) for x, y in pkg_data if y]
pkg_data = [(x, y.encode('utf-8')) for x, y in pkg_data if y]
return redirect("/packages/?%s" % urlencode(pkg_data))
def groups(request, arch=None):