Skip to content

Commit 878e2b7

Browse files
author
Karan Mitroo
authored
Making whitelist and blacklist case insensitive (#5)
* Making whitelist and blacklist case insensitive * Updated README.rst mentioning case insensitive match
1 parent 405c658 commit 878e2b7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Usages
3838
3939
**is\_safe\_username** takes the following optional arguments:
4040

41-
- ``whitelist``: a list of words that should be considered as always
41+
- ``whitelist``: a case insensitive list of words that should be considered as always
4242
safe. Default: ``[]``
43-
- ``blacklist``: a list of words that should be considered as unsafe. Default: ``[]``
43+
- ``blacklist``: a case insensitive list of words that should be considered as unsafe. Default: ``[]``
4444
- ``max_length``: specify the maximun character a username can have. Default: ``None``
4545
- ``regex``: regular expression string that must pass before the banned
4646
words is checked.

usernames/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def is_safe_username(
2828
if not re.match(regex, username):
2929
return False
3030
wordlist = get_reserved_wordlist()
31-
whitelist = set(whitelist)
32-
blacklist = set(blacklist)
31+
whitelist = set([each_whitelisted_name.lower() for each_whitelisted_name in whitelist])
32+
blacklist = set([each_blacklisted_name.lower() for each_blacklisted_name in blacklist])
3333
wordlist = wordlist - whitelist
3434
wordlist = wordlist.union(blacklist)
3535
return False if username.lower() in wordlist else True

0 commit comments

Comments
 (0)