From 7e2bd414af6629477c4f4813eaedc2608282be62 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 19 May 2012 12:10:22 +0200 Subject: [PATCH] Fixed #18340 -- Fixed formtools form_hmac with Unicode input Using cPickle, two apparently identical Unicode strings could generate different pickled results depending on previous operations on those strings. --- formtools/tests/__init__.py | 7 ++----- formtools/utils.py | 6 ++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/formtools/tests/__init__.py b/formtools/tests/__init__.py index 88828e8..bf06846 100644 --- a/formtools/tests/__init__.py +++ b/formtools/tests/__init__.py @@ -156,9 +156,6 @@ class PreviewTests(TestCase): class FormHmacTests(unittest.TestCase): - """ - Same as SecurityHashTests, but with form_hmac - """ def test_textfield_hash(self): """ @@ -166,8 +163,8 @@ class FormHmacTests(unittest.TestCase): 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) diff --git a/formtools/utils.py b/formtools/utils.py index 572a096..96a0092 100644 --- a/formtools/utils.py +++ b/formtools/utils.py @@ -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