From b04fa5812146916e3035f32b9c23bec39aead800 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):