Skip to content

Commit

Permalink
Fixed #18340 -- Fixed formtools form_hmac with Unicode input
Browse files Browse the repository at this point in the history
Using cPickle, two apparently identical Unicode strings could
generate different pickled results depending on previous operations
on those strings.
  • Loading branch information
claudep committed May 19, 2012
1 parent 2aebd79 commit 1a66f53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 2 additions & 5 deletions django/contrib/formtools/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,15 @@ def test_form_submit_bad_hash(self):


class FormHmacTests(unittest.TestCase):
"""
Same as SecurityHashTests, but with form_hmac
"""

def test_textfield_hash(self):
"""
Regression test for #10034: the hash generation function should ignore
leading/trailing whitespace so as to be friendly to broken browsers that
submit it (usually in textareas).
"""
f1 = HashTestForm({'name': 'joe', 'bio': 'Nothing notable.'})
f2 = HashTestForm({'name': ' joe', 'bio': 'Nothing notable. '})
f1 = HashTestForm({'name': u'joe', 'bio': u'Nothing notable.'})
f2 = HashTestForm({'name': u' joe', 'bio': u'Nothing notable. '})
hash1 = utils.form_hmac(f1)
hash2 = utils.form_hmac(f2)
self.assertEqual(hash1, hash2)
Expand Down
6 changes: 2 additions & 4 deletions django/contrib/formtools/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
try:
import cPickle as pickle
except ImportError:
import pickle
# Do not try cPickle here (see #18340)
import pickle

from django.utils.crypto import salted_hmac

Expand Down

0 comments on commit 1a66f53

Please sign in to comment.