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>
This commit is contained in:
committed by
Igor Lins e Silva
parent
976289aa5c
commit
b1a676fa24
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user