From aece5ce7a62ddc1d7fd1f39fc55d6b85b085cd1c Mon Sep 17 00:00:00 2001 From: Tuomas Haapala Date: Thu, 29 Jan 2026 12:10:40 +0200 Subject: [PATCH] fix(search): skip empty operands in search query builder Refs: PL-210 --- services/search/api.py | 3 +++ services/search/tests/test_api.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/services/search/api.py b/services/search/api.py index 6997d3ce4..fc7717538 100644 --- a/services/search/api.py +++ b/services/search/api.py @@ -241,6 +241,9 @@ def build_search_query(query: str): and_operands = re.split(r"[\s,&]+", or_operand) expression = "" for and_operand in and_operands: + if not and_operand.strip(): + # Skip empty or whitespace-only operands + continue if re.fullmatch(r"'+", and_operand): # Skip any operands that are just repeating single-quotes continue diff --git a/services/search/tests/test_api.py b/services/search/tests/test_api.py index ff3c7efa2..d76f69500 100644 --- a/services/search/tests/test_api.py +++ b/services/search/tests/test_api.py @@ -262,6 +262,16 @@ def test_search_with_vertical_bar_in_query(api_client, units): ("a, &&& , & b || || |||| |c,,,, d", "a:* & b:* | c:* & d:*"), # Expression with repeating single-quotes ("','','''',a,b'c,d''e,f'''g,','','''", "a:* & b'c:* & d''e:* & f'''g:*"), + # Empty operands should be skipped to prevent invalid ":*" syntax + (" ", ""), + (" | ", ""), + (" & ", ""), + (" , ", ""), + ("a | | b", "a:* | b:*"), + ("a & & b", "a:* & b:*"), + ("a, ,b", "a:* & b:*"), + (" | a", "a:*"), + ("a | ", "a:*"), ], ) def test_build_search_query(query, expected):