diff --git a/homeassistant/core.py b/homeassistant/core.py index d95c25d93e2..1b1849ba548 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1723,13 +1723,13 @@ class Config: # In 2021.9 we fixed validation to disallow a path (because that's never correct) # but this data still lives in storage, so we print a warning. - if "external_url" in data and urlparse(data["external_url"]).path not in ( + if data.get("external_url") and urlparse(data["external_url"]).path not in ( "", "/", ): _LOGGER.warning("Invalid external_url set. It's not allowed to have a path") - if "internal_url" in data and urlparse(data["internal_url"]).path not in ( + if data.get("internal_url") and urlparse(data["internal_url"]).path not in ( "", "/", ): diff --git a/tests/test_core.py b/tests/test_core.py index df66fedd025..641a5e0dfda 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1377,6 +1377,18 @@ async def test_additional_data_in_core_config(hass, hass_storage): async def test_incorrect_internal_external_url(hass, hass_storage, caplog): """Test that we warn when detecting invalid internal/extenral url.""" config = ha.Config(hass) + + hass_storage[ha.CORE_STORAGE_KEY] = { + "version": 1, + "data": { + "internal_url": None, + "external_url": None, + }, + } + await config.async_load() + assert "Invalid external_url set" not in caplog.text + assert "Invalid internal_url set" not in caplog.text + hass_storage[ha.CORE_STORAGE_KEY] = { "version": 1, "data": {