Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with non ascii username submission #60

Open
dlancer opened this issue Jun 18, 2016 · 7 comments
Open

Problem with non ascii username submission #60

dlancer opened this issue Jun 18, 2016 · 7 comments

Comments

@dlancer
Copy link

dlancer commented Jun 18, 2016

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)

@kencochrane
Copy link
Collaborator

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.

@jedie
Copy link

jedie commented Nov 10, 2016

Why not use from __future__ import unicode_literals ?

@kencochrane
Copy link
Collaborator

@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
Copy link
Collaborator

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

@MattBlack85
Copy link
Contributor

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

@kencochrane
Copy link
Collaborator

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.

@nupur2099
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants