From 536f0a4488ffd9358c1869af596361870a459ace Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 19 Jan 2023 12:23:49 -0700 Subject: [PATCH] Limit shortcodes on emoji to Mastodon rules --- users/views/admin/emoji.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/users/views/admin/emoji.py b/users/views/admin/emoji.py index a108d13..9053cee 100644 --- a/users/views/admin/emoji.py +++ b/users/views/admin/emoji.py @@ -1,5 +1,6 @@ from django import forms from django.conf import settings +from django.core.validators import RegexValidator from django.db import models from django.shortcuts import redirect from django.utils.decorators import method_decorator @@ -46,7 +47,10 @@ class EmojiCreate(FormView): class form_class(forms.Form): shortcode = forms.SlugField( - help_text="What users type to use the emoji :likethis:", + help_text="What users type to use the emoji :likethis:\nShould only contain 0-9, a-z and underscores", + validators=[ + RegexValidator(r"^[a-z0-9_]+$", message="Invalid emoji shortcode") + ], ) image = forms.ImageField( help_text=f"The emoji image\nShould be at least 40 x 40 pixels, and under {settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB}KB",