mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-24 20:35:55 +00:00
Replace non-unicode characters for add-on static files (#5712)
* Replace non-unicode characters for add-on static files Add-on documentation and changelog get read and returned as text file. However, in case the original author used non-unicode characters, or the file corrupted, loading currently fails with an UnicodeDecodeError. Let's just use the built-in replace error handling of Python, so they appear for the user as non-unicode characters by replacing them with the official unicode replacement character "�". * Remove superflous parameter for binary files * ruff format * Add pytests
This commit is contained in:
@@ -349,3 +349,41 @@ async def test_repository_not_found(api_client: TestClient, method: str, url: st
|
||||
assert resp.status == 404
|
||||
body = await resp.json()
|
||||
assert body["message"] == "Repository bad does not exist in the store"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("resource", ["store/addons", "addons"])
|
||||
async def test_api_store_addons_documentation_corrupted(
|
||||
api_client: TestClient, coresys: CoreSys, store_addon: AddonStore, resource: str
|
||||
):
|
||||
"""Test /store/addons/{addon}/documentation REST API.
|
||||
|
||||
Test add-on with documentation file with byte sequences which cannot be decoded
|
||||
using UTF-8.
|
||||
"""
|
||||
store_addon.path_documentation.write_bytes(b"Text with an invalid UTF-8 char: \xff")
|
||||
await store_addon.refresh_path_cache()
|
||||
assert store_addon.with_documentation is True
|
||||
|
||||
resp = await api_client.get(f"/{resource}/{store_addon.slug}/documentation")
|
||||
assert resp.status == 200
|
||||
result = await resp.text()
|
||||
assert result == "Text with an invalid UTF-8 char: <20>"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("resource", ["store/addons", "addons"])
|
||||
async def test_api_store_addons_changelog_corrupted(
|
||||
api_client: TestClient, coresys: CoreSys, store_addon: AddonStore, resource: str
|
||||
):
|
||||
"""Test /store/addons/{addon}/changelog REST API.
|
||||
|
||||
Test add-on with changelog file with byte sequences which cannot be decoded
|
||||
using UTF-8.
|
||||
"""
|
||||
store_addon.path_changelog.write_bytes(b"Text with an invalid UTF-8 char: \xff")
|
||||
await store_addon.refresh_path_cache()
|
||||
assert store_addon.with_changelog is True
|
||||
|
||||
resp = await api_client.get(f"/{resource}/{store_addon.slug}/changelog")
|
||||
assert resp.status == 200
|
||||
result = await resp.text()
|
||||
assert result == "Text with an invalid UTF-8 char: <20>"
|
||||
|
||||
Reference in New Issue
Block a user