Prevent leading and trailing spaces in translation values (#126427)

* Prevent leading and trailing spaces in translation values

* Adjust components

* Tests
This commit is contained in:
epenet 2024-09-22 16:01:08 +02:00 committed by GitHub
parent 90957dfedb
commit 7c5dc29981
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 12 deletions

View File

@ -131,11 +131,13 @@ def translation_value_validator(value: Any) -> str:
- prevents strings with single quoted placeholders - prevents strings with single quoted placeholders
- prevents combined translations - prevents combined translations
""" """
value = cv.string_with_no_html(value) string_value = cv.string_with_no_html(value)
value = string_no_single_quoted_placeholders(value) string_value = string_no_single_quoted_placeholders(string_value)
if RE_COMBINED_REFERENCE.search(value): if RE_COMBINED_REFERENCE.search(string_value):
raise vol.Invalid("the string should not contain combined translations") raise vol.Invalid("the string should not contain combined translations")
return str(value) if string_value != string_value.strip(" "):
raise vol.Invalid("the string should not contain leading or trailing spaces")
return string_value
def string_no_single_quoted_placeholders(value: str) -> str: def string_no_single_quoted_placeholders(value: str) -> str: