Skip to content
This repository
Browse code

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

…-of-firefox
  • Loading branch information...
commit 6ae48116d6e6eb20b654fe5d897514a1246525ae 1 parent 0412986
Les Orchard authored October 14, 2011
14  apps/actioncounters/tests.py
@@ -56,6 +56,20 @@ def mk_request(self, user=None, ip='192.168.123.123',
56 56
         request.META['HTTP_USER_AGENT'] = user_agent
57 57
         return request
58 58
 
  59
+    @attr('bug694544')
  60
+    def test_bug694544(self):
  61
+        """Bug 694544: unicode character in request details should not break"""
  62
+        try:
  63
+            action_name = "likes"
  64
+            obj_1 = self.obj_1
  65
+            obj_1_ct = ContentType.objects.get_for_model(obj_1)
  66
+
  67
+            request = self.mk_request(user_agent=u"Some\xef\xbf\xbdbrowser")
  68
+            user, ip, user_agent, unique_hash = get_unique(obj_1_ct, obj_1.pk,
  69
+                                                           action_name, request)
  70
+        except UnicodeDecodeError:
  71
+            ok_(False, "UnicodeDecodeError should not be thrown")
  72
+
59 73
     @attr('bad_multiple')
60 74
     def test_bad_multiple_counters(self):
61 75
         """Force multiple counters, possibly result of race condition, ensure graceful handling"""
2  apps/actioncounters/utils.py
@@ -61,7 +61,7 @@ def get_unique(content_type, object_pk, name, request=None, ip=None, user_agent=
61 61
     # HACK: Build a hash of the fields that should be unique, let MySQL
62 62
     # chew on that for a unique index. Note that any changes to this algo
63 63
     # will create all new unique hashes that don't match any existing ones.
64  
-    hash_text = "\n".join(unicode(x) for x in (
  64
+    hash_text = "\n".join(unicode(x).encode('utf8') for x in (
65 65
         content_type.pk, object_pk, name, ip, user_agent, 
66 66
         (user and user.pk or 'None')
67 67
     ))
13  apps/contentflagging/tests.py
@@ -49,6 +49,19 @@ def mk_request(self, user=None, ip='192.168.123.123',
49 49
         request.META['HTTP_USER_AGENT'] = user_agent
50 50
         return request
51 51
 
  52
+    @attr('bug694544')
  53
+    def test_bug694544(self):
  54
+        """Bug 694544: unicode character in request details should not break"""
  55
+        try:
  56
+            request = self.mk_request(user_agent=u"Some\xef\xbf\xbdbrowser")
  57
+
  58
+            obj_1 = self.user2
  59
+            obj_1_ct = ContentType.objects.get_for_model(obj_1)
  60
+            user, ip, user_agent, unique_hash = get_unique(obj_1_ct, obj_1.pk,
  61
+                                                       request=request)
  62
+        except UnicodeDecodeError:
  63
+            ok_(False, "UnicodeDecodeError should not be thrown")
  64
+
52 65
     @attr('bad_multiple')
53 66
     def test_bad_multiple_flags(self):
54 67
         """Force multiple flags, possibly result of race condition, ensure graceful handling"""
2  apps/contentflagging/utils.py
@@ -60,7 +60,7 @@ def get_unique(content_type, object_pk, request=None, ip=None, user_agent=None,
60 60
     # HACK: Build a hash of the fields that should be unique, let MySQL
61 61
     # chew on that for a unique index. Note that any changes to this algo
62 62
     # will create all new unique hashes that don't match any existing ones.
63  
-    hash_text = "\n".join(unicode(x) for x in (
  63
+    hash_text = "\n".join(unicode(x).encode('utf8') for x in (
64 64
         content_type.pk, object_pk, ip, user_agent, 
65 65
         (user and user.pk or 'None')
66 66
     ))

0 notes on commit 6ae4811

Please sign in to comment.
Something went wrong with that request. Please try again.