Skip to content

Commit 2bfc3ba

Browse files
committed
fixes regex strips
1 parent c5028b2 commit 2bfc3ba

File tree

1 file changed

+13
-3
lines changed
  • services/web/server/src/simcore_service_webserver/products

1 file changed

+13
-3
lines changed

services/web/server/src/simcore_service_webserver/products/_model.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,40 @@ class Product(BaseModel):
111111

112112
@validator("*", pre=True)
113113
@classmethod
114-
def parse_empty_string_as_null(cls, v):
114+
def _parse_empty_string_as_null(cls, v):
115115
"""Safe measure: database entries are sometimes left blank instead of null"""
116116
if isinstance(v, str) and len(v.strip()) == 0:
117117
return None
118118
return v
119119

120120
@validator("name", pre=True, always=True)
121121
@classmethod
122-
def validate_name(cls, v):
122+
def _validate_name(cls, v):
123123
if v not in FRONTEND_APPS_AVAILABLE:
124124
msg = f"{v} is not in available front-end apps {FRONTEND_APPS_AVAILABLE}"
125125
raise ValueError(msg)
126126
return v
127127

128+
@validator("host_regex", pre=True)
129+
@classmethod
130+
def _strip_whitespaces(cls, v):
131+
if v and isinstance(v, str):
132+
# Prevents unintended leading & trailing spaces when added
133+
# manually in the database
134+
return v.strip()
135+
return v
136+
128137
@property
129138
def twilio_alpha_numeric_sender_id(self) -> str:
130139
return self.short_name or self.display_name.replace(string.punctuation, "")[:11]
131140

132141
class Config:
133142
alias_generator = snake_to_camel # to export
134143
allow_population_by_field_name = True
144+
anystr_strip_whitespace = True
145+
extra = Extra.ignore
135146
frozen = True # read-only
136147
orm_mode = True
137-
extra = Extra.ignore
138148
schema_extra: ClassVar[dict[str, Any]] = {
139149
"examples": [
140150
{

0 commit comments

Comments
 (0)