Fix FTS5 crashes when searching with special characters

Always wrap FTS5 query terms in phrase double-quotes instead of
checking a hardcoded list of special characters. Characters like
|, ;, +, #, @ were missing from the list, causing FTS5 syntax
errors (production errors #1 and #1398). Phrase-quoting every term
produces identical results for normal ASCII search (verified via
SQL) while safely handling any character FTS5 chokes on.

Add regression tests for bare special characters and special
characters mixed with normal words.
This commit is contained in:
Claudio Ortolina
2026-05-05 12:05:12 +01:00
parent c87e725b05
commit ba2566828c
2 changed files with 24 additions and 6 deletions
+2 -6
View File
@@ -47,12 +47,8 @@ defmodule MusicLibrary.Records.Search do
end
defp fts_escape(term) do
if String.contains?(term, ["'", " ", "\"", "(", ")", "^", "-", ":", "?", ".", "&"]) do
escaped = String.replace(term, "\"", "\"\"")
"\"#{escaped}\"*"
else
"#{term}*"
end
escaped = String.replace(term, "\"", "\"\"")
"\"#{escaped}\"*"
end
defp fts_query_escape(query) do