Skip to content

Commit 781d610

Browse files
timgrahamWaVEV
authored andcommitted
amend valid_path_key_name() to reject only dollar signs and periods
1 parent 2b04427 commit 781d610

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

django_mongodb_backend/fields/json.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
)
1919

2020
from django_mongodb_backend.lookups import builtin_lookup_expr, builtin_lookup_path
21-
from django_mongodb_backend.query_utils import process_lhs, process_rhs, valid_path_key_name
21+
from django_mongodb_backend.query_utils import process_lhs, process_rhs
22+
23+
24+
def valid_path_key_name(key_name):
25+
# A value can use path syntax (field.subfield.) unless it contains a
26+
# dollar sign or period.
27+
return not any(char in key_name for char in ("$", "."))
2228

2329

2430
def build_json_mql_path(lhs, key_transforms, as_expr=False):

django_mongodb_backend/query_utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import re
2-
31
from django.core.exceptions import FullResultSet
42
from django.db.models.aggregates import Aggregate
53
from django.db.models.expressions import CombinedExpression, Func, Value
@@ -82,7 +80,3 @@ def is_constant_value(value):
8280
# Allow Func with can_use_path as a temporary exception.
8381
(isinstance(value, Func) and value.can_use_path)
8482
)
85-
86-
87-
def valid_path_key_name(key_name):
88-
return bool(re.fullmatch(r"[A-Za-z0-9_]+", key_name))

0 commit comments

Comments
 (0)