#18340: formtools.utils.form_hmac is not consistent with unicode input
---------------------------------------------+------------------------
Reporter: claudep | Owner: nobody
Type: Bug | Status: new
Component: contrib.formtools | Version: master
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
This problem can only be reproduced with cPickle. When feeding the
django.contrib.formtools.utils.form_hmac function with Unicode values,
stripping the leading/ending spaces produces different pickled results
than the unstripped identical values. Here is an output of the two
form_hmac passes in the !FormHmacTests.test_textfield_hash when you
convert form values to Unicode:
{{{
(Pdb) p data, pickled
([('name', u'joe'), ('bio', u'Nothing notable.')],
'\x80\x02]q\x01(U\x04nameq\x02X\x03\x00\x00\x00joeq\x03\x86q\x04U\x03bioq\x05X\x10\x00\x00\x00Nothing
notable.q\x06\x86q\x07e.')
(Pdb) p data, pickled
([('name', u'joe'), ('bio', u'Nothing notable.')],
'\x80\x02]q\x01(U\x04nameq\x02X\x03\x00\x00\x00joe\x86q\x03U\x03bioq\x04X\x10\x00\x00\x00Nothing
notable.q\x05\x86q\x06e.')
}}}
Possible workarounds:
* use the (slower) pickle module only, as I don't think the performance
penalty will be noticeable in this part of the code
* encode all unicode values to 'utf-8' (smart_str) before feeding them to
pickle.dumps
* feed repr(data) to pickle.dumps
--
Ticket URL: <https://code.djangoproject.com/ticket/18340>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.