12 lines
395 B
JavaScript
12 lines
395 B
JavaScript
// https://manual.manticoresearch.com/Searching/Full_text_matching/Escaping#Escaping-characters-in-query-string
|
|
export default function escape(string) {
|
|
if (!string) {
|
|
return null;
|
|
}
|
|
|
|
return string
|
|
.replace(/\\/g, String.raw`\\\\`) // using String.raw so we don't have to double up JS and SQL escaping
|
|
.replace(/'/g, String.raw`\'`)
|
|
.replace(/(["!$()/<@^|~-])/g, String.raw`\\$1`);
|
|
}
|