blob: 10519a4137170bff2c187b72fefb8202221829eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import re
FTS_META_CHARS = r'''["'*()^+-]''' # include ? if you see issues
def sanitize_query(q: str, *, allow_ops: bool = False) -> str:
q = q.strip()
if not q:
return q
if allow_ops:
# escape stray double quotes inside, then wrap
q = q.replace('"', '""')
return f'"{q}"'
# literal search: quote and escape special chars
q = re.sub(r'"', '""', q)
return f'"{q}"'
|