From 2f1507c31a7d2d58213334657efadbd96dfdc94b Mon Sep 17 00:00:00 2001 From: relhamdi Date: Mon, 25 May 2026 11:17:50 +0200 Subject: [PATCH] Fix removing empty elements to avoid trailing commas --- src/utils.py | 3 ++- tests/test_parse_options.py | 4 +++- web/prompt_option_picker.js | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils.py b/src/utils.py index 68c9434..2844c73 100644 --- a/src/utils.py +++ b/src/utils.py @@ -60,7 +60,8 @@ def parse_options(raw: str) -> list[str]: # Generate cartesian product for combo in product(*current_block): - result.append(", ".join(combo)) + parts = [p for p in combo if p.strip()] + result.append(", ".join(parts) if parts else "") elif stripped == "---": if in_combine: diff --git a/tests/test_parse_options.py b/tests/test_parse_options.py index 34329c4..a4daf00 100644 --- a/tests/test_parse_options.py +++ b/tests/test_parse_options.py @@ -43,8 +43,10 @@ def test_combine_three_lists(): def test_combine_empty_line_in_list(): raw = "@combine\na\n\n---\nb\n@end" result = parse_options(raw) - assert ", b" in result # empty + b + assert "b" in result assert "a, b" in result + # Empty element combined with b gives just "b" + assert ", b" not in result def test_multiple_combine_blocks(): diff --git a/web/prompt_option_picker.js b/web/prompt_option_picker.js index 7a59a39..db0e7c3 100644 --- a/web/prompt_option_picker.js +++ b/web/prompt_option_picker.js @@ -75,7 +75,8 @@ const parseOptions = (raw) => { const next = []; for (const a of acc) { for (const b of list) { - next.push(a ? `${a}, ${b}` : b); + const parts = [a, b].filter((p) => p.trim() !== ""); + next.push(parts.join(", ")); } } return next;