From f4bf8fa8f13a4c4525e7b00078ed8a5097f68d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 1 Oct 2023 17:19:24 +0300 Subject: [PATCH] Catch HTML case insensitively in "no HTML" config validation (#101181) --- homeassistant/components/owntracks/strings.json | 2 +- homeassistant/helpers/config_validation.py | 2 +- tests/helpers/test_config_validation.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/owntracks/strings.json b/homeassistant/components/owntracks/strings.json index 2486e01223f..499b598d7ae 100644 --- a/homeassistant/components/owntracks/strings.json +++ b/homeassistant/components/owntracks/strings.json @@ -11,7 +11,7 @@ "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" }, "create_entry": { - "default": "\n\nOn Android, open [the OwnTracks app]({android_url}), go to Preferences > Connection. Change the following settings:\n - Mode: HTTP\n - Host: {webhook_url}\n - Identification:\n - Username: `''`\n - Device ID: `''`\n\nOn iOS, open [the OwnTracks app]({ios_url}), tap (i) icon in top left > Settings. Change the following settings:\n - Mode: HTTP\n - URL: {webhook_url}\n - Turn on authentication\n - UserID: `''`\n\n{secret}\n\nSee [the documentation]({docs_url}) for more information." + "default": "\n\nOn Android, open [the OwnTracks app]({android_url}), go to Preferences > Connection. Change the following settings:\n - Mode: HTTP\n - Host: {webhook_url}\n - Identification:\n - Username: `'(Your name)'`\n - Device ID: `'(Your device name)'`\n\nOn iOS, open [the OwnTracks app]({ios_url}), tap (i) icon in top left > Settings. Change the following settings:\n - Mode: HTTP\n - URL: {webhook_url}\n - Turn on authentication\n - UserID: `'(Your name)'`\n\n{secret}\n\nSee [the documentation]({docs_url}) for more information." } } } diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index a4018101d0e..eed57e7ea25 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -599,7 +599,7 @@ def string(value: Any) -> str: 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]*>") + regex = re.compile(r"<[a-z].*?>", re.IGNORECASE) if regex.search(value): raise vol.Invalid("the string should not contain HTML") return str(value) diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index 80fc1bf2241..a9ddd89a0b3 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -563,6 +563,9 @@ def test_string_with_no_html() -> None: with pytest.raises(vol.Invalid): schema("Bold") + with pytest.raises(vol.Invalid): + schema("HTML element names are case-insensitive.") + for value in ( True, 3,