Generic camera: Allow svg detect to accept leading whitespace (#68932)

This commit is contained in:
Dave T 2022-03-30 23:45:55 +01:00 committed by GitHub
parent d25f7e1376
commit 3244980a35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -114,7 +114,7 @@ def get_image_type(image):
if fmt is None:
# if imghdr can't figure it out, could be svg.
with contextlib.suppress(UnicodeDecodeError):
if image.decode("utf-8").startswith("<svg"):
if image.decode("utf-8").lstrip().startswith("<svg"):
return "svg+xml"
return fmt

View File

@ -110,6 +110,21 @@ async def test_form_only_stillimage(hass, fakeimg_png, user_flow):
assert respx.calls.call_count == 1
@respx.mock
async def test_form_only_svg_whitespace(hass, fakeimgbytes_svg, user_flow):
"""Test we complete ok if svg starts with whitespace, issue #68889."""
fakeimgbytes_wspace_svg = bytes(" \n ", encoding="utf-8") + fakeimgbytes_svg
respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_wspace_svg)
data = TESTDATA.copy()
data.pop(CONF_STREAM_SOURCE)
result2 = await hass.config_entries.flow.async_configure(
user_flow["flow_id"],
data,
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@respx.mock
async def test_form_rtsp_mode(hass, fakeimg_png, mock_av_open, user_flow):
"""Test we complete ok if the user enters a stream url."""