Closed Bug 564385 Opened 16 years ago Closed 16 years ago

[k] crc32 filters throw UnicodeEncodeError's on non-ASCII characters

Categories

(support.mozilla.org :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: paulc, Assigned: paulc)

References

()

Details

Wherever we use crc32, passing unicode to it causes problems. STR: 1. Go to: http://support.mozilla.com/en-US/search?a=1&tags=日##語 More detail (from stack trace): File "/data/www/support.mozilla.com/kitsune/apps/search/views.py", line 213, in search tags = [crc32(t.strip()) for t in cleaned['tags'].split()] File "/data/www/support.mozilla.com/kitsune/apps/search/utils.py", line 7, in <lambda> crc32 = lambda x: zlib.crc32(x) & 0xffffffff UnicodeEncodeError: 'ascii' codec can't encode character u'\u65e5' in position 0: ordinal not in range(128)
Figured this out! The problem is that zlib.crc32 (as well as binascii.crc32) expect binary data, not unicode. Turning a utf-8 string into binary in python is as simple as: mystr.encode('utf-8') This resource helped: http://boodebr.org/main/python/all-about-python-and-unicode#UNI_TO_BINARY I updated the search URL. Testing with the tag 有効, I got the article below as a search result: Cookie を有効または無効にする r? at: http://github.com/pcraciunoiu/kitsune/commit/8ec1514049cd201782a649f35cfc698d8233508e
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.