mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
upload: Fix docstring and regex in sanitize_name regarding underscore.
Underscore character is already covered by \w, so _ in the regex is redundant. Also the docstring is mildly incorrect - underscore already is an allowed character by django's slugify (and always was) for the aforementioned reason.
This commit is contained in:
committed by
Tim Abbott
parent
1d9fb4f988
commit
389c7bdb5a
@@ -87,11 +87,11 @@ def sanitize_name(value: str) -> str:
|
||||
|
||||
This implementation is based on django.utils.text.slugify; it is
|
||||
modified by:
|
||||
* adding '.' and '_' to the list of allowed characters.
|
||||
* adding '.' to the list of allowed characters.
|
||||
* preserving the case of the value.
|
||||
"""
|
||||
value = unicodedata.normalize("NFKC", value)
|
||||
value = re.sub(r"[^\w\s._-]", "", value, flags=re.U).strip()
|
||||
value = re.sub(r"[^\w\s.-]", "", value, flags=re.U).strip()
|
||||
value = re.sub(r"[-\s]+", "-", value, flags=re.U)
|
||||
assert value not in {"", ".", ".."}
|
||||
return mark_safe(value)
|
||||
|
||||
Reference in New Issue
Block a user