From 389c7bdb5aaaace86b9ce57803746fccdd277342 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 2 May 2021 14:42:23 +0200 Subject: [PATCH] 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. --- zerver/lib/upload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zerver/lib/upload.py b/zerver/lib/upload.py index d4fabe146f..c4756d43f9 100644 --- a/zerver/lib/upload.py +++ b/zerver/lib/upload.py @@ -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)