2309: infobox throws UnicodeEncodeError when user has non US-ASCII characters in name

bo.bj******@gmai***** (Google Code) (Is this you? Claim this profile.)
Jan. 24, 2012
2377
What version are you running?
1.6.1

What's the URL of the page containing the problem?
/users/<some user with non US-ASCII characters in full name>/infobox/

What steps will reproduce the problem?
1. Create a user with non US-ASCII characters in either first name or last name or both.
2. Submit a review as this user.
3. Navigate to this review.
4. Mouse over the submitters name to get the pop-up infobox.

What is the expected output? What do you see instead?
Expected output is the infobox with the users details (user name, full name, user email, etc), actual output is a "Something broke (error 500)" error message.

What operating system are you using? What browser?
Reviewboard is served by a Arch Linux VM, via apache. Browser is Chromium (14.0.835.186) and Firefox (6.0.2) on Arch Linux.

Please provide any additional information below.
This would not bother me as much as we do not really use this feature (small in-house review board at work), the annoying thing is that it sends me an e-mail every time someone accidentally mouses over pretty much any of our user names - we're Norwegians, so names tend to contain strange and unusual letters ;)

Exception with backtrace:
Internal Server Error: /users/bjorn/infobox/
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.6.1-py2.7.egg/reviewboard/accounts/decorators.py", line 21, in _check
    return view_func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.6.1-py2.7.egg/reviewboard/reviews/views.py", line 1166, in user_infobox
    set_etag(response, etag)
  File "/usr/lib/python2.7/site-packages/Djblets-0.6.11-py2.7.egg/djblets/util/http.py", line 68, in set_etag
    response['ETag'] = etag
  File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/http/__init__.py", line 533, in __setitem__
    header, value = self._convert_to_ascii(header, value)
  File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/http/__init__.py", line 522, in _convert_to_ascii
    value = value.encode('us-ascii')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in position 2: ordinal not in range(128), HTTP response headers must be in US-ASCII format
#1 bo.bj******@gmai***** (Google Code) (Is this you? Claim this profile.)
And it is probably worth noting that the infobox works as expected with the one submitter we have with only US-ASCII letters in his name.
#2 mueg*****@gmai***** (Google Code) (Is this you? Claim this profile.)
Hi guys!

I've just found a fast solution for this problem with simply replacing the special characters with their webwide used xml form before Django tries to encode them into ASCII...

The modified "reviewboard\reviews\views.py" script, where I fixed this bug, is attached to my comment.

ps.: I'm already using 1.6.2, but the bug is existing there as well.
  • +
    import logging
    import time
    from datetime import datetime
    from django.conf import settings
    from django.contrib.auth.models import User
    from django.contrib.sites.models import Site
    from django.core.urlresolvers import reverse
    from django.db.models import Q
    from django.http import HttpResponse, HttpResponseRedirect, Http404, \
                            HttpResponseNotModified, HttpResponseServerError
    from django.shortcuts import get_object_or_404, get_list_or_404, \
                                 render_to_response
    from django.template.context import RequestContext
    from django.template.loader import render_to_string
    from django.utils import simplejson
    from django.utils.http import http_date
    from django.utils.safestring import mark_safe
    from django.utils.translation import ugettext as _
    from django.views.decorators.cache import cache_control
    from django.views.generic.list_detail import object_list
    from djblets.auth.util import login_required
    from djblets.siteconfig.models import SiteConfigur
#3 bo.bj******@gmai***** (Google Code) (Is this you? Claim this profile.)
There is a fix for this issue in the Reviewboard:
http://reviews.reviewboard.org/r/2657/

It is pending unit tests to avoid regressions.
#5 mueg*****@gmai***** (Google Code) (Is this you? Claim this profile.)
Thanks,

I've viewed the bugfix, but according to http://docs.python.org/howto/unicode.html 'replace' replaces everything with a '?' character, however 'xmlcharrefreplace' replaces everything with it's XML form, which practically means, that special characters will remain the same when they are displayed on the webpage.

So maybe using 'xmlcharrefreplace' would be a better solution :) Or does 'replace' keep the original names?
david
#7 david
Fixed in release-1.6.x (731c0f6). Thanks!
  • +Fixed