diff --git a/imgutils/sd/metadata.py b/imgutils/sd/metadata.py index 1ceca5e5c0a..ae83d9412c6 100644 --- a/imgutils/sd/metadata.py +++ b/imgutils/sd/metadata.py @@ -195,7 +195,13 @@ def parse_sdmeta_from_text(x: str) -> SDMetaData: """ x = textwrap.dedent(x).strip() - *prompt_lines, argument_line = x.splitlines(keepends=False) + all_lines = x.splitlines(keepends=False) + if len(all_lines) >= 1: + prompt_lines = all_lines[:-1] + argument_line = all_lines[-1] + else: + prompt_lines = [] + argument_line = '' if len(_PARAM_PATTERN.findall(argument_line)) < 3: prompt_lines.append(argument_line) argument_line = '' diff --git a/test/sd/test_metadata.py b/test/sd/test_metadata.py index 30dbefea788..0c485b9192c 100644 --- a/test/sd/test_metadata.py +++ b/test/sd/test_metadata.py @@ -397,3 +397,6 @@ def _test_pnginfo(pinfo): assert get_sdmeta_from_image(f) == sdimg_3_std with _test_pnginfo(sdimg_4_std.pnginfo) as f: assert get_sdmeta_from_image(f) == sdimg_4_std + + def test_empty_info_parse(self): + assert parse_sdmeta_from_text('') == SDMetaData('', '', {})