Fix domain validation in Tesla Fleet (#148555)

This commit is contained in:
jlestel 2025-07-11 01:41:03 +02:00 committed by GitHub
parent e6702d2392
commit 193b32218f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -226,5 +226,7 @@ class OAuth2FlowHandler(
def _is_valid_domain(self, domain: str) -> bool:
"""Validate domain format."""
# Basic domain validation regex
domain_pattern = re.compile(r"^(?:[a-zA-Z0-9]+\.)+[a-zA-Z0-9-]+$")
domain_pattern = re.compile(
r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$"
)
return bool(domain_pattern.match(domain))

View File

@ -713,8 +713,11 @@ async def test_reauth_confirm_form(hass: HomeAssistant) -> None:
("domain", "expected_valid"),
[
("example.com", True),
("exa-mple.com", True),
("test.example.com", True),
("tes-t.example.com", True),
("sub.domain.example.org", True),
("su-b.dom-ain.exam-ple.org", True),
("https://example.com", False),
("invalid-domain", False),
("", False),
@ -722,6 +725,8 @@ async def test_reauth_confirm_form(hass: HomeAssistant) -> None:
("example.", False),
(".example.com", False),
("exam ple.com", False),
("-example.com", False),
("domain-.example.com", False),
],
)
def test_is_valid_domain(domain: str, expected_valid: bool) -> None: