mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add check for HTML in translations (#35615)
* Add check for HTML in translations and remove existing html * Add test
This commit is contained in:
@@ -465,6 +465,15 @@ def string(value: Any) -> str:
|
||||
return str(value)
|
||||
|
||||
|
||||
def string_with_no_html(value: Any) -> str:
|
||||
"""Validate that the value is a string without HTML."""
|
||||
value = string(value)
|
||||
regex = re.compile(r"<[a-z][\s\S]*>")
|
||||
if regex.search(value):
|
||||
raise vol.Invalid("the string should not contain HTML")
|
||||
return str(value)
|
||||
|
||||
|
||||
def temperature_unit(value: Any) -> str:
|
||||
"""Validate and transform temperature unit."""
|
||||
value = str(value).upper()
|
||||
|
||||
Reference in New Issue
Block a user