From ea025f812c57313b15b73d2f828756d5c87826e8 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 25 Mar 2024 16:45:15 -0400 Subject: [PATCH] Refactor UserProfilePhotoForm to strip leading period from file extension --- users/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/users/forms.py b/users/forms.py index c78d9849..b4da0e69 100644 --- a/users/forms.py +++ b/users/forms.py @@ -123,8 +123,11 @@ class UserProfilePhotoForm(forms.ModelForm): if self.cleaned_data.get("image"): new_image = self.cleaned_data["image"] _, file_extension = os.path.splitext(new_image.name) - new_image.name = f"{user.profile_image_filename_root}.{file_extension}" + # Strip the leading period from the file extension. + file_extension = file_extension.lstrip(".") + + new_image.name = f"{user.profile_image_filename_root}.{file_extension}" user.image = new_image if commit: