From b1a676fa246a1cd3c931064a10abc3d6fc95687f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Apr 2026 22:26:41 +0000 Subject: [PATCH] fix: make quote trimming explicit Agent-Logs-Url: https://github.com/MemPalace/mempalace/sessions/775f2fc4-3051-462e-8586-6d694b55da0d Co-authored-by: igorls <4753812+igorls@users.noreply.github.com> --- mempalace/query_sanitizer.py | 10 +++++++--- tests/test_query_sanitizer.py | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mempalace/query_sanitizer.py b/mempalace/query_sanitizer.py index f86a621..b320e9c 100644 --- a/mempalace/query_sanitizer.py +++ b/mempalace/query_sanitizer.py @@ -69,11 +69,15 @@ def sanitize_query(raw_query: str) -> dict: def _strip_wrapping_quotes(candidate: str) -> str: candidate = candidate.strip() - while candidate[:1] in {"'", '"'} and candidate[-1:] in {"'", '"'}: - candidate = candidate.strip("\"'") + while len(candidate) >= 2 and candidate[:1] in {"'", '"'} and candidate[-1:] in {"'", '"'}: + candidate = candidate[1:-1].strip() if not candidate: return "" - return candidate.strip("\"'") + if candidate[:1] in {"'", '"'}: + candidate = candidate[1:].strip() + if candidate[-1:] in {"'", '"'}: + candidate = candidate[:-1].strip() + return candidate def _trim_candidate(candidate: str) -> str: candidate = _strip_wrapping_quotes(candidate) diff --git a/tests/test_query_sanitizer.py b/tests/test_query_sanitizer.py index 015a8a1..dd96cfa 100644 --- a/tests/test_query_sanitizer.py +++ b/tests/test_query_sanitizer.py @@ -112,6 +112,7 @@ class TestTailSentence: query = ("Prefix text " * 30) + '\n"' + ("x" * 260) + '"' result = sanitize_query(query) assert result["method"] == "tail_sentence" + assert result["clean_query"] == "x" * MAX_QUERY_LENGTH assert not result["clean_query"].startswith('"') assert not result["clean_query"].endswith('"') assert len(result["clean_query"]) <= MAX_QUERY_LENGTH