From 1bbc1f5f55de29bef86edbf7e504298c3d51bdc8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 18 Feb 2022 16:11:17 -0800 Subject: [PATCH] Validate in split_entity_id (#66835) --- homeassistant/components/logbook/__init__.py | 4 ++-- homeassistant/core.py | 7 +++++-- tests/helpers/test_entity_registry.py | 18 +++++++++--------- tests/test_core.py | 12 +++++++++++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/logbook/__init__.py b/homeassistant/components/logbook/__init__.py index 1af10039772..28b0460ac7a 100644 --- a/homeassistant/components/logbook/__init__.py +++ b/homeassistant/components/logbook/__init__.py @@ -71,7 +71,7 @@ GROUP_BY_MINUTES = 15 EMPTY_JSON_OBJECT = "{}" UNIT_OF_MEASUREMENT_JSON = '"unit_of_measurement":' -HA_DOMAIN_ENTITY_ID = f"{HA_DOMAIN}." +HA_DOMAIN_ENTITY_ID = f"{HA_DOMAIN}._" CONFIG_SCHEMA = vol.Schema( {DOMAIN: INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA}, extra=vol.ALLOW_EXTRA @@ -598,7 +598,7 @@ def _keep_event(hass, event, entities_filter): if domain is None: return False - return entities_filter is None or entities_filter(f"{domain}.") + return entities_filter is None or entities_filter(f"{domain}._") def _augment_data_with_context( diff --git a/homeassistant/core.py b/homeassistant/core.py index 38a0bbeb73c..27dba3cbc52 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -141,9 +141,12 @@ TIMEOUT_EVENT_START = 15 _LOGGER = logging.getLogger(__name__) -def split_entity_id(entity_id: str) -> list[str]: +def split_entity_id(entity_id: str) -> tuple[str, str]: """Split a state entity ID into domain and object ID.""" - return entity_id.split(".", 1) + domain, _, object_id = entity_id.partition(".") + if not domain or not object_id: + raise ValueError(f"Invalid entity ID {entity_id}") + return domain, object_id VALID_ENTITY_ID = re.compile(r"^(?!.+__)(?!_)[\da-z_]+(?