From d03141635cfe73e85937e5ce6b21957268931ca0 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 12 Nov 2023 13:23:59 +0200 Subject: [PATCH] Don't strip separators from join results we didn't add in the first place (#107) Fixes #106 Refs https://github.com/adieyal/sd-dynamic-prompts/discussions/672 --- src/dynamicprompts/sampling_result.py | 13 ++++++++++++- tests/test_sd_issues.py | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/dynamicprompts/sampling_result.py b/src/dynamicprompts/sampling_result.py index 2667198..3603c6f 100644 --- a/src/dynamicprompts/sampling_result.py +++ b/src/dynamicprompts/sampling_result.py @@ -35,7 +35,18 @@ def joined( ) -> SamplingResult: from dynamicprompts.utils import removeprefix, removesuffix - joined = separator.join(r.text for r in results) + results_list = list(results) + + if len(results_list) == 1: + # Special case: when we have a single result, + # there's no point in joining anything, or doing + # the special handling to strip separators (since + # we never added any). This means that a separator + # in the input will be preserved; this is intentional. + return results_list[0] + + joined = separator.join(r.text for r in results_list) + if separator: joined = removeprefix(joined, separator) joined = removesuffix(joined, separator) diff --git a/tests/test_sd_issues.py b/tests/test_sd_issues.py index 31542d2..f30f576 100644 --- a/tests/test_sd_issues.py +++ b/tests/test_sd_issues.py @@ -138,3 +138,11 @@ def test_sd_665(): wi = list(_parse_structured_file_list([expr])) assert len(wi) == 1 assert wi[0] == expr + + +def test_sd_672(wildcard_manager: WildcardManager): + # https://github.com/adieyal/sd-dynamic-prompts/discussions/672 + + tpl = "{|hot,}{|summer,}{|blue sky,}" + generator = CombinatorialPromptGenerator(wildcard_manager) + assert any("," in prompt for prompt in generator.generate(tpl))