Make sure that hyperparam/configuration/metadata keys that are contain only empty space are rejected

This commit is contained in:
allegroai 2023-11-17 09:32:22 +02:00
parent 2263e7cc1e
commit d0252a6dd9

View File

@ -1,6 +1,8 @@
from boltons.dictutils import OneToOne
from mongoengine.queryset.transform import MATCH_OPERATORS
from apiserver.apierrors import errors
class ParameterKeyEscaper:
"""
@ -15,8 +17,13 @@ class ParameterKeyEscaper:
@classmethod
def escape(cls, value: str):
""" Quote a parameter key """
value = value.strip().replace("%", "%%")
value = value.strip()
if not value:
raise errors.bad_request.ValidationError(
f"Empty key is not allowed"
)
value = value.replace("%", "%%")
for c, r in cls._mapping.items():
value = value.replace(c, r)