Skip to content

Commit ea58867

Browse files
fix: get-identities-checks-existing-invalid-identifiers (#6083)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a6621a5 commit ea58867

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

api/environments/identities/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from django.core.validators import RegexValidator
44

5-
RE_VALID_IDENTIFIER = re.compile(r"^[\w!#$%&*+/=?^_`{}|~@.\-]+$")
5+
RE_VALID_IDENTIFIER = re.compile(r"^[\w !#$%&*+/=?^_`{}|~@.\-]+$")
66

77
identifier_regex_validator = RegexValidator(
88
regex=RE_VALID_IDENTIFIER,
9-
message="Identifier can only contain unicode letters, numbers, and the symbols: ! # $ %% & * + / = ? ^ _ ` { } | ~ @ . -",
9+
message="Identifier can only contain unicode letters, numbers, spaces and the symbols: ! # $ %% & * + / = ? ^ _ ` { } | ~ @ . -",
1010
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 4.2.24 on 2025-09-17 16:24
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
import re
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
("identities", "0003_sanitized_identifiers"),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name="identity",
17+
name="identifier",
18+
field=models.CharField(
19+
max_length=2000,
20+
validators=[
21+
django.core.validators.RegexValidator(
22+
message="Identifier can only contain unicode letters, numbers, spaces and the symbols: ! # $ %% & * + / = ? ^ _ ` { } | ~ @ . -",
23+
regex=re.compile("^[\\w !#$%&*+/=?^_`{}|~@.\\-]+$"),
24+
)
25+
],
26+
),
27+
),
28+
]

api/tests/unit/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
2323
"identifier",
2424
[
2525
"bond...jamesbond",
26+
"identity with spaces",
2627
"ゴジラ",
2728
"ElChapulínColorado",
2829
"dalek#6453@skaro.gov",
@@ -36,13 +37,12 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
3637
)
3738

3839
if metafunc.definition.get_closest_marker("invalid_identity_identifiers"):
39-
error_message = "Identifier can only contain unicode letters, numbers, and the symbols: ! # $ % & * + / = ? ^ _ ` { } | ~ @ . -"
40+
error_message = "Identifier can only contain unicode letters, numbers, spaces and the symbols: ! # $ % & * + / = ? ^ _ ` { } | ~ @ . -"
4041
metafunc.parametrize(
4142
["identifier", "identifier_error_message"],
4243
[
4344
("", "This field may not be blank."),
4445
(" ", "This field may not be blank."),
45-
("or really anything with a whitespace", error_message),
4646
("<script>alert(1)</script>", error_message),
4747
("'; DROP TABLE users;--", error_message),
4848
("'single-quotes'", error_message),

0 commit comments

Comments
 (0)