Fix: Valiation of values with trailing spaces
This commit is contained in:
parent
50ec2d08c0
commit
f254b0ea46
@ -8,14 +8,14 @@ from definitions.attributes import *
|
|||||||
def create_text_field(attrib: textAttribute) -> fields.String:
|
def create_text_field(attrib: textAttribute) -> fields.String:
|
||||||
"""Create a Marshmallow String field for textAttribute."""
|
"""Create a Marshmallow String field for textAttribute."""
|
||||||
def validate_allowed_chars(value: str, attrib=attrib) -> None:
|
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):
|
if attrib.allowed_chars and not all(char in attrib.allowed_chars for char in value.strip()):
|
||||||
raise ValidationError(f"Invalid characters in {attrib.display_name}. Allowed characters are: {attrib.allowed_chars}")
|
raise ValidationError(f"Invalid characters in {attrib.display_name}. Allowed characters are: {attrib.allowed_chars}")
|
||||||
|
|
||||||
return fields.String(
|
return fields.String(
|
||||||
required=attrib.required,
|
required=attrib.required,
|
||||||
validate=[
|
validate=[
|
||||||
lambda x, attrib=attrib: len(x) <= attrib.max_length if attrib.max_length else True,
|
lambda x, attrib=attrib: len(x.strip()) <= 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: len(x.strip()) >= attrib.min_length if attrib.min_length else True,
|
||||||
lambda x, attrib=attrib: re.match(attrib.regex, x) if attrib.regex else True,
|
lambda x, attrib=attrib: re.match(attrib.regex, x) if attrib.regex else True,
|
||||||
validate_allowed_chars,
|
validate_allowed_chars,
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user