Permalink
Browse files

Bug 694544 - [Django] Error (EXTERNAL IP): /de/demos/detail/tomoshibi…

…-of-firefox
  • Loading branch information...
1 parent 0412986 commit 6ae48116d6e6eb20b654fe5d897514a1246525ae @lmorchard lmorchard committed Oct 14, 2011
Showing with 29 additions and 2 deletions.
  1. +14 −0 apps/actioncounters/tests.py
  2. +1 −1 apps/actioncounters/utils.py
  3. +13 −0 apps/contentflagging/tests.py
  4. +1 −1 apps/contentflagging/utils.py
@@ -56,6 +56,20 @@ def mk_request(self, user=None, ip='192.168.123.123',
request.META['HTTP_USER_AGENT'] = user_agent
return request
+ @attr('bug694544')
+ def test_bug694544(self):
+ """Bug 694544: unicode character in request details should not break"""
+ try:
+ action_name = "likes"
+ obj_1 = self.obj_1
+ obj_1_ct = ContentType.objects.get_for_model(obj_1)
+
+ request = self.mk_request(user_agent=u"Some\xef\xbf\xbdbrowser")
+ user, ip, user_agent, unique_hash = get_unique(obj_1_ct, obj_1.pk,
+ action_name, request)
+ except UnicodeDecodeError:
+ ok_(False, "UnicodeDecodeError should not be thrown")
+
@attr('bad_multiple')
def test_bad_multiple_counters(self):
"""Force multiple counters, possibly result of race condition, ensure graceful handling"""
@@ -61,7 +61,7 @@ def get_unique(content_type, object_pk, name, request=None, ip=None, user_agent=
# HACK: Build a hash of the fields that should be unique, let MySQL
# chew on that for a unique index. Note that any changes to this algo
# will create all new unique hashes that don't match any existing ones.
- hash_text = "\n".join(unicode(x) for x in (
+ hash_text = "\n".join(unicode(x).encode('utf8') for x in (
content_type.pk, object_pk, name, ip, user_agent,
(user and user.pk or 'None')
))
@@ -49,6 +49,19 @@ def mk_request(self, user=None, ip='192.168.123.123',
request.META['HTTP_USER_AGENT'] = user_agent
return request
+ @attr('bug694544')
+ def test_bug694544(self):
+ """Bug 694544: unicode character in request details should not break"""
+ try:
+ request = self.mk_request(user_agent=u"Some\xef\xbf\xbdbrowser")
+
+ obj_1 = self.user2
+ obj_1_ct = ContentType.objects.get_for_model(obj_1)
+ user, ip, user_agent, unique_hash = get_unique(obj_1_ct, obj_1.pk,
+ request=request)
+ except UnicodeDecodeError:
+ ok_(False, "UnicodeDecodeError should not be thrown")
+
@attr('bad_multiple')
def test_bad_multiple_flags(self):
"""Force multiple flags, possibly result of race condition, ensure graceful handling"""
@@ -60,7 +60,7 @@ def get_unique(content_type, object_pk, request=None, ip=None, user_agent=None,
# HACK: Build a hash of the fields that should be unique, let MySQL
# chew on that for a unique index. Note that any changes to this algo
# will create all new unique hashes that don't match any existing ones.
- hash_text = "\n".join(unicode(x) for x in (
+ hash_text = "\n".join(unicode(x).encode('utf8') for x in (
content_type.pk, object_pk, ip, user_agent,
(user and user.pk or 'None')
))

0 comments on commit 6ae4811

Please sign in to comment.