1
0
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:
Bram Kragten
2020-05-14 19:33:14 +02:00
committed by GitHub
parent a42a654590
commit cb7b8d94c0
7 changed files with 47 additions and 18 deletions

View File

@@ -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()