Skip to content

Commit d4f2673

Browse files
committed
Revert "use supplied regex"
This reverts commit 178020c.
1 parent 40ce2d8 commit d4f2673

2 files changed

Lines changed: 12 additions & 135 deletions

File tree

server/Pipfile.lock

Lines changed: 0 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/mergin/auth/forms.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright (C) Lutra Consulting Limited
22
#
33
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
4-
5-
import regex
4+
import re
65
import safe
76
from flask_wtf import FlaskForm
87
from sqlalchemy import func
@@ -18,6 +17,7 @@
1817

1918
from .models import MAX_USERNAME_LENGTH, User
2019
from ..app import UpdateForm, CustomStringField
20+
from .utils import get_email_domain
2121

2222

2323
def username_validation(form, field):
@@ -57,20 +57,19 @@ class ExtendedEmail(Email):
5757
because they make our email sending service to fail
5858
"""
5959

60-
EMAIL_PATTERN = regex.compile(
61-
r"""(?i)^[\x60#&*\/=?^{!}~'_\p{L}0-9\-\+]+
62-
(\.[\x60#&*\/=?^{!}~'_\p{L}0-9\-\+]+)*\.?@
63-
([_a-z0-9-]+(\.[_a-z0-9-]+)*\.)
64-
[a-z0-9-]*[a-z0-9]{2,}$""",
65-
regex.VERBOSE,
66-
)
67-
6860
def __call__(self, form, field):
6961
super().__call__(form, field)
7062

71-
value = field.data.strip()
72-
if not self.EMAIL_PATTERN.match(value):
73-
raise ValidationError(f"Email address '{value}' is invalid.")
63+
if re.search(r"[|'—]", field.data):
64+
raise ValidationError(
65+
f"Email address '{field.data}' contains an invalid character."
66+
)
67+
68+
domain = get_email_domain(field.data)
69+
if not domain.isascii():
70+
raise ValidationError(
71+
f"Email address '{field.data}' contains non-ASCII characters in the domain part."
72+
)
7473

7574

7675
class PasswordValidator:

0 commit comments

Comments
 (0)