From c75e30fd2860f146ed9d1604cc688b1db850a0c6 Mon Sep 17 00:00:00 2001 From: jonaswinkler <17569239+jonaswinkler@users.noreply.github.com> Date: Thu, 25 Feb 2021 11:30:49 +0100 Subject: [PATCH] validate hex color strings --- src/documents/serialisers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 4d52f496b..689e2fe8d 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -171,6 +171,12 @@ class TagSerializer(MatchingModelSerializer): "document_count" ) + def validate_color(self, color): + regex = r"#[0-9a-fA-F]{6}" + if not re.match(regex, color): + raise serializers.ValidationError(_("Invalid color.")) + return color + class CorrespondentField(serializers.PrimaryKeyRelatedField): def get_queryset(self):