diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 182001310ad..55d2fa21934 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -24,6 +24,11 @@ RE_REFERENCE = r"\[\%key:(.+)\%\]" RE_TRANSLATION_KEY = re.compile(r"^(?!.+[_-]{2})(?![_-])[a-z0-9-_]+(? 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 diff --git a/tests/hassfest/test_translations.py b/tests/hassfest/test_translations.py index bce815decbd..87a38a1352d 100644 --- a/tests/hassfest/test_translations.py +++ b/tests/hassfest/test_translations.py @@ -411,3 +411,21 @@ def test_gen_strings_schema( validated = schema(SAMPLE_STRINGS) assert validated == SAMPLE_STRINGS + + +@pytest.mark.parametrize( + "translation_string", + [ + "An example is: https://example.com.", + "www.example.com", + "http://example.com:8080", + "WWW.EXAMPLE.COM", + "HTTPS://www.example.com", + ], +) +def test_no_placeholders_used_for_urls(translation_string: str) -> None: + """Test that translation strings containing URLs are rejected.""" + schema = vol.Schema(translations.translation_value_validator) + + with pytest.raises(vol.Invalid): + schema(translation_string)