MCPcopy Create free account
hub / github.com/MemTensor/MemOS / sanitizeFtsQuery

Function sanitizeFtsQuery

packages/memos-core/src/storage/sqlite.ts:2888–2897  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

2886 * with implicit AND (space-separated) for safe querying.
2887 */
2888function 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
2899const FTS_RESERVED = new Set(["AND", "OR", "NOT", "NEAR"]);
2900

Callers 6

ftsSearchMethod · 0.70
skillFtsSearchMethod · 0.70
taskFtsSearchMethod · 0.70
searchHubChunksMethod · 0.70
searchHubSkillsMethod · 0.70
searchHubMemoriesMethod · 0.70

Calls 4

filterMethod · 0.80
mapMethod · 0.80
hasMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected