Skip to content

Commit

Permalink
test unicode harder (bug 681351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Balogh committed Aug 24, 2011
1 parent 4358959 commit 3374eef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/users/helpers.py
@@ -1,7 +1,8 @@
import random

import jinja2
from django.utils.encoding import smart_unicode

import jinja2
from jingo import register, env
from tower import ugettext as _

Expand Down Expand Up @@ -56,7 +57,7 @@ def _user_link(user):
if isinstance(user, basestring):
return user
return u'<a href="%s">%s</a>' % (
user.get_url_path(), unicode(jinja2.escape(user.name)))
user.get_url_path(), jinja2.escape(smart_unicode(user.name)))


@register.filter
Expand Down
8 changes: 6 additions & 2 deletions apps/users/tests/test_helpers.py
Expand Up @@ -70,7 +70,11 @@ def test_short_users_list():

def test_user_link_unicode():
"""make sure helper won't choke on unicode input"""
u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller',
pk=1)
u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1)
eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' %
reverse('users.profile', args=[1]))

u = UserProfile(username='\xe5\xaf\x92\xe6\x98\x9f', pk=1)
url = reverse('users.profile', args=[1])
eq_(user_link(u),
u'<a href="%s">%s</a>' % (url, u.username.decode('utf-8')))

0 comments on commit 3374eef

Please sign in to comment.