mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 03:16:37 +00:00
Tolerate malformed repository/description metadata instead of crashing
This commit is contained in:
committed by
J. Nick Koston
parent
1f5152892c
commit
d80d2c7034
@@ -240,12 +240,17 @@ def generate_idf_component_yml(component: IDFComponent) -> str:
|
|||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
|
# Metadata only: tolerate malformed shapes instead of crashing on a
|
||||||
|
# third-party manifest (repository may legally be {"url": ...} or a
|
||||||
|
# plain URL string)
|
||||||
description = component.data.get("description")
|
description = component.data.get("description")
|
||||||
if description:
|
if isinstance(description, str) and description:
|
||||||
data["description"] = description
|
data["description"] = description
|
||||||
|
|
||||||
repository = component.data.get("repository", {}).get("url", None)
|
repository = component.data.get("repository")
|
||||||
if repository:
|
if isinstance(repository, dict):
|
||||||
|
repository = repository.get("url")
|
||||||
|
if isinstance(repository, str) and repository:
|
||||||
data["repository"] = repository
|
data["repository"] = repository
|
||||||
|
|
||||||
for dependency in component.dependencies:
|
for dependency in component.dependencies:
|
||||||
|
|||||||
@@ -374,6 +374,18 @@ def test_generate_idf_component_yml_basic(tmp_component):
|
|||||||
assert result == "description: test\nrepository: http://aaa\n"
|
assert result == "description: test\nrepository: http://aaa\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_idf_component_yml_tolerates_malformed_metadata(tmp_component):
|
||||||
|
"""A string repository is the URL itself; junk shapes drop instead of
|
||||||
|
crashing on a third-party manifest."""
|
||||||
|
tmp_component.data = {"description": "test", "repository": "http://aaa"}
|
||||||
|
assert (
|
||||||
|
generate_idf_component_yml(tmp_component)
|
||||||
|
== "description: test\nrepository: http://aaa\n"
|
||||||
|
)
|
||||||
|
tmp_component.data = {"description": {"en": "x"}, "repository": 123}
|
||||||
|
assert generate_idf_component_yml(tmp_component) == "{}\n"
|
||||||
|
|
||||||
|
|
||||||
def test_generate_idf_component_yml_with_dependencies(tmp_component, tmp_path):
|
def test_generate_idf_component_yml_with_dependencies(tmp_component, tmp_path):
|
||||||
dep = IDFComponent("dep", "1.0", source=URLSource("http://dummy.com"))
|
dep = IDFComponent("dep", "1.0", source=URLSource("http://dummy.com"))
|
||||||
dep.path = tmp_path / "dep"
|
dep.path = tmp_path / "dep"
|
||||||
|
|||||||
Reference in New Issue
Block a user