mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-12 07:49:39 -05:00
Allow only ascii characters
This commit is contained in:
parent
ad61786b0f
commit
2ef15395d4
@ -49,6 +49,15 @@ class ChatModeWeb:
|
|||||||
self.define_routes()
|
self.define_routes()
|
||||||
|
|
||||||
def remove_unallowed_characters(self, text):
|
def remove_unallowed_characters(self, text):
|
||||||
|
"""
|
||||||
|
Sanitize username to remove unwanted characters.
|
||||||
|
Allowed characters right now are:
|
||||||
|
- all ASCII numbers
|
||||||
|
- all ASCII letters
|
||||||
|
- dash, underscore and single space
|
||||||
|
"""
|
||||||
|
|
||||||
|
def allowed_character(ch):
|
||||||
allowed_unicode_categories = [
|
allowed_unicode_categories = [
|
||||||
'L', # All letters
|
'L', # All letters
|
||||||
'N', # All numbers
|
'N', # All numbers
|
||||||
@ -58,9 +67,9 @@ class ChatModeWeb:
|
|||||||
'_', # underscore
|
'_', # underscore
|
||||||
' ', # single space
|
' ', # single space
|
||||||
]
|
]
|
||||||
|
return (
|
||||||
def allowed_character(ch):
|
unicodedata.category(ch)[0] in allowed_unicode_categories and ord(ch) < 128
|
||||||
return unicodedata.category(ch)[0] in allowed_unicode_categories or ch in allowed_special_characters
|
) or ch in allowed_special_characters
|
||||||
|
|
||||||
return "".join(
|
return "".join(
|
||||||
ch for ch in text if allowed_character(ch)
|
ch for ch in text if allowed_character(ch)
|
||||||
|
Loading…
Reference in New Issue
Block a user