django-defender icon indicating copy to clipboard operation
django-defender copied to clipboard

Problem with non ascii username submission

Open dlancer opened this issue 8 years ago • 7 comments

python 2.7 Django 1.8.13 django-defender 0.4.2

I cannot cleanup username filed, because defender handle post data before form validation, so if user submit non ascii username - defender raise UnicodeEncodeError exception.

"utils.py", line 68, in get_username_blocked_cache_key
    return "{0}:blocked:username:{1}".format(config.CACHE_PREFIX, username)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

dlancer avatar Jun 18 '16 13:06 dlancer

It looks like .format() is chocking on unicode characters. It should be this instead.

return u"{0}:blocked:username:{1}".format(config.CACHE_PREFIX, username)

If you want to submit a PR with this fix, that would be very helpful. We should also add a unit test for usernames with non ascii characters.

kencochrane avatar Jun 20 '16 12:06 kencochrane

Why not use from __future__ import unicode_literals ?

jedie avatar Nov 10 '16 10:11 jedie

@jedie not sure, I have to admit I'm horrible when it comes to unicode. If you feel that is the best way, feel free to submit a PR, and we can fix.

kencochrane avatar Nov 10 '16 13:11 kencochrane

Is this still a problem, or has it been fixed with one of the recent releases?

kencochrane avatar Jul 01 '17 13:07 kencochrane

I'm not able to reproduce this on python2, it would be nice to know which username had been passed around, I tried also to add a failing test but the test is passing

MattBlack85 avatar Jul 03 '17 18:07 MattBlack85

hmm, maybe it was already fixed. It is probably a good idea to have a unit test with the unicode character as a regression test, incase we accidentally break it again in the future.

kencochrane avatar Jul 03 '17 18:07 kencochrane

how to write 60° in python because ° sign show error Your submission contains non ASCII characters, we don't accept submissions with non ASCII characters for this challenge.

nupur2099 avatar Sep 19 '21 21:09 nupur2099