Skip to content

Commit 178020c

Browse files
committed
use supplied regex
1 parent 8635e5e commit 178020c

File tree

3 files changed

+137
-13
lines changed

3 files changed

+137
-13
lines changed

server/Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typing_extensions = "==4.12.2"
4242
python-magic = "==0.4.27"
4343
# requirements for development on windows
4444
colorama = "==0.4.5"
45+
regex = "2025.11.3"
4546

4647
[dev-packages]
4748
pytest = "==8.3.2"

server/Pipfile.lock

Lines changed: 123 additions & 1 deletion
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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Copyright (C) Lutra Consulting Limited
22
#
33
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
4-
import re
4+
5+
import regex
56
import safe
67
from flask_wtf import FlaskForm
78
from sqlalchemy import func
@@ -17,7 +18,6 @@
1718

1819
from .models import MAX_USERNAME_LENGTH, User
1920
from ..app import UpdateForm, CustomStringField
20-
from .utils import get_email_domain
2121

2222

2323
def username_validation(form, field):
@@ -57,19 +57,20 @@ 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+
6068
def __call__(self, form, field):
6169
super().__call__(form, field)
6270

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-
)
71+
value = field.data.strip()
72+
if not self.EMAIL_PATTERN.match(value):
73+
raise ValidationError(f"Email address '{value}' is invalid.")
7374

7475

7576
class PasswordValidator:

0 commit comments

Comments
 (0)