Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/api/plane/app/serializers/user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Python imports
import re


# Third party imports
from rest_framework import serializers

Expand All @@ -7,16 +11,29 @@

from .base import BaseSerializer

# Regex pattern to block the following special characters in names:
# & + , : ; $ ^ } { * = ? @ # | ' < > . ( ) % !

FORBIDDEN_NAME_CHARS_PATTERN = r"^.*[&+,:;$^}{*=?@#|'<>.()%!].*$"


class UserSerializer(BaseSerializer):
def validate_first_name(self, value):
if contains_url(value):
raise serializers.ValidationError("First name cannot contain a URL.")

if re.match(FORBIDDEN_NAME_CHARS_PATTERN, value):
raise serializers.ValidationError("First name cannot contain special characters.")

return value

def validate_last_name(self, value):
if contains_url(value):
raise serializers.ValidationError("Last name cannot contain a URL.")

if re.match(FORBIDDEN_NAME_CHARS_PATTERN, value):
raise serializers.ValidationError("Last name cannot contain special characters.")

return value

class Meta:
Expand Down
Loading