From b774427e9c5b23dd3dab6b2bf072ba3359fd93f8 Mon Sep 17 00:00:00 2001
From: candifloss <candifloss@candifloss.cc>
Date: Sat, 15 Mar 2025 10:06:34 +0530
Subject: [PATCH] "Allowed chars" validation for `textAttribute`

---
 functions/validate_values.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/functions/validate_values.py b/functions/validate_values.py
index 2159269..53469f6 100644
--- a/functions/validate_values.py
+++ b/functions/validate_values.py
@@ -13,12 +13,18 @@ def create_dynamic_schema() -> Type[Schema]:
 
     for attrib in item_attributes:
         if isinstance(attrib, textAttribute):
+            # Allowed chars
+            def validate_allowed_chars(value: str, attrib=attrib) -> None:
+                if attrib.allowed_chars and not all(char in attrib.allowed_chars for char in value):
+                    raise ValidationError(f"Invalid characters in {attrib.display_name}. Allowed characters are: {attrib.allowed_chars}")
+                    
             schema_fields[attrib.attrib_name] = fields.String(
                 required=attrib.required,
                 validate=[
                     lambda x, attrib=attrib: len(x) <= attrib.max_length if attrib.max_length else True,
                     lambda x, attrib=attrib: len(x) >= attrib.min_length if attrib.min_length else True,
                     lambda x, attrib=attrib: re.match(attrib.regex, x) if attrib.regex else True,
+                    validate_allowed_chars,
                 ],
                 error_messages={
                     "required": f"{attrib.display_name} is required.",