MCPcopy
hub / github.com/streetwriters/notesnook / escapeSQLString

Function escapeSQLString

packages/core/src/utils/query-transformer.ts:120–147  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

118
119const INVALID_QUERY_REGEX = /[!"#$%&'()*+,\-./:;<>=?@[\\\]^_`{|}~§]/;
120function escapeSQLString(str: string): string {
121 if (str.startsWith('"') && str.endsWith('"')) {
122 const innerStr = str.slice(1, -1).replace(/"/g, '""');
123 return `"${innerStr}"`;
124 }
125
126 const hasInvalidSymbol = INVALID_QUERY_REGEX.test(str);
127 const isWildcard =
128 str.startsWith("*") ||
129 str.endsWith("*") ||
130 str.startsWith("%") ||
131 str.endsWith("%");
132 if (hasInvalidSymbol || isWildcard) {
133 return `"${str}"`;
134 }
135
136 // if (isWildcard) {
137 // return str.replace(/(.+?)(\*?$)/gm, (_, text, end) => {
138 // return `${escapeSQLString(text)}${end}`;
139 // });
140 // }
141
142 // if (str.includes("-")) {
143 // return `"${str.replace(/"/g, '""')}"`;
144 // }
145
146 return str.replace(/"/g, '""');
147}
148
149function tokenizeWithFields(
150 query: string

Callers

nothing calls this directly

Calls 2

sliceMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected