fix: escape SQL wildcards in tag search autocomplete

The % and _ characters in user search input are now escaped before
the LIKE query, preventing unintended wildcard matching in tag search.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-06 00:26:35 -05:00
parent 94ec19cf07
commit 1e57aa8323
2 changed files with 33 additions and 1 deletions

View File

@@ -62,8 +62,9 @@ async def search_tags(
Searches tag names for the query string.
Returns matching tags ordered by usage count.
"""
escaped_q = q.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
query = select(TreeTag).where(
TreeTag.name.ilike(f"%{q}%")
TreeTag.name.ilike(f"%{escaped_q}%", escape="\\")
)
# Filter by visibility