* Sanitize user input for FTS5 MATCH queries. * Strip FTS operators and special characters, then join tokens * with implicit AND (space-separated) for safe querying.
(raw: string)
| 2886 | * with implicit AND (space-separated) for safe querying. |
| 2887 | */ |
| 2888 | function sanitizeFtsQuery(raw: string): string { |
| 2889 | const tokens = raw |
| 2890 | .replace(/[."""(){}[\]*:^~!@#$%&\\/<>,;'`-]/g, " ") |
| 2891 | .split(/\s+/) |
| 2892 | .map((t) => t.trim().replace(/^-+|-+$/g, "")) |
| 2893 | .filter((t) => t.length > 1) |
| 2894 | .filter((t) => !FTS_RESERVED.has(t.toUpperCase())); |
| 2895 | |
| 2896 | return tokens.join(" "); |
| 2897 | } |
| 2898 | |
| 2899 | const FTS_RESERVED = new Set(["AND", "OR", "NOT", "NEAR"]); |
| 2900 |
no test coverage detected