diff -r 0d75d06731df django/contrib/messages/storage/cookie.py
a
|
b
|
|
1 | 1 | import hmac |
| 2 | import base64 |
2 | 3 | |
3 | 4 | from django.conf import settings |
4 | 5 | from django.utils.hashcompat import sha_hmac |
… |
… |
|
114 | 115 | """ |
115 | 116 | if messages or encode_empty: |
116 | 117 | encoder = MessageEncoder(separators=(',', ':')) |
117 | | value = encoder.encode(messages) |
| 118 | value = base64.b64encode(encoder.encode(messages)) |
118 | 119 | return '%s$%s' % (self._hash(value), value) |
119 | 120 | |
120 | 121 | def _decode(self, data): |
… |
… |
|
133 | 134 | try: |
134 | 135 | # If we get here (and the JSON decode works), everything is |
135 | 136 | # good. In any other case, drop back and return None. |
136 | | return json.loads(value, cls=MessageDecoder) |
| 137 | return json.loads(base64.b64decode(value), |
| 138 | cls=MessageDecoder) |
137 | 139 | except ValueError: |
138 | 140 | pass |
139 | 141 | # Mark the data as used (so it gets removed) since something was wrong |
diff -r 0d75d06731df django/contrib/messages/tests/cookie.py
a
|
b
|
|
70 | 70 | response = self.get_response() |
71 | 71 | |
72 | 72 | for i in range(5): |
73 | | storage.add(constants.INFO, str(i) * 900) |
| 73 | # 1.33 = increase in size due to base64 encoding |
| 74 | # 4k = max cookie size |
| 75 | # 675 * 4 * 1.33 = 3591 |
| 76 | # 675 * 5 * 1.33 = 4489 |
| 77 | storage.add(constants.INFO, str(i) * 675) |
74 | 78 | unstored_messages = storage.update(response) |
75 | 79 | |
76 | 80 | cookie_storing = self.stored_messages_count(storage, response) |
77 | 81 | self.assertEqual(cookie_storing, 4) |
78 | 82 | |
79 | 83 | self.assertEqual(len(unstored_messages), 1) |
80 | | self.assert_(unstored_messages[0].message == '0' * 900) |
| 84 | self.assert_(unstored_messages[0].message == '0' * 675) |
81 | 85 | |
82 | 86 | def test_json_encoder_decoder(self): |
83 | 87 | """ |
diff -r 0d75d06731df django/contrib/messages/tests/fallback.py
a
|
b
|
|
148 | 148 | response = self.get_response() |
149 | 149 | |
150 | 150 | for i in range(5): |
151 | | storage.add(constants.INFO, str(i) * 900) |
| 151 | # 1.33 = increase in size due to base64 encoding |
| 152 | # 4k = max cookie size |
| 153 | # 675 * 4 * 1.33 = 3591 |
| 154 | # 675 * 5 * 1.33 = 4489 |
| 155 | storage.add(constants.INFO, str(i) * 675) |
152 | 156 | storage.update(response) |
153 | 157 | |
154 | 158 | cookie_storing = self.stored_cookie_messages_count(storage, response) |