mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Don't translate URLs (#154224)
Co-authored-by: jbouwh <jan@jbsoft.nl> Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2dc1981932
commit
36b9234f26
@@ -24,6 +24,11 @@ RE_REFERENCE = r"\[\%key:(.+)\%\]"
|
||||
RE_TRANSLATION_KEY = re.compile(r"^(?!.+[_-]{2})(?![_-])[a-z0-9-_]+(?<![_-])$")
|
||||
RE_COMBINED_REFERENCE = re.compile(r"(.+\[%)|(%\].+)")
|
||||
RE_PLACEHOLDER_IN_SINGLE_QUOTES = re.compile(r"'{\w+}'")
|
||||
RE_URL = re.compile(
|
||||
r"(((ftp|ftps|scp|http|https|mqtt|mqtts|socket|socks5):\/\/|www\.)"
|
||||
r"[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?)",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# Only allow translation of integration names if they contain non-brand names
|
||||
ALLOW_NAME_TRANSLATION = {
|
||||
@@ -143,6 +148,11 @@ def validate_translation_value(value: Any, allow_placeholders=True) -> str:
|
||||
raise vol.Invalid("the string should not contain combined translations")
|
||||
if string_value != string_value.strip():
|
||||
raise vol.Invalid("the string should not contain leading or trailing spaces")
|
||||
if RE_URL.search(string_value):
|
||||
raise vol.Invalid(
|
||||
"the string should not contain URLs, "
|
||||
"please use description placeholders instead"
|
||||
)
|
||||
return string_value
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user