@coasys/ad4m 0.11.2-dev-sdna-only-prolog → 0.11.2-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +232 -164
- package/lib/index.js +232 -165
- package/lib/src/model/Ad4mModel.js +36 -41
- package/lib/src/model/Subject.js +2 -47
- package/lib/src/perspectives/PerspectiveProxy.d.ts +20 -1
- package/lib/src/perspectives/PerspectiveProxy.js +143 -54
- package/lib/src/utils.d.ts +23 -0
- package/lib/src/utils.js +31 -0
- package/package.json +9 -14
- package/src/model/Ad4mModel.ts +37 -42
- package/src/model/Subject.ts +2 -43
- package/src/perspectives/PerspectiveProxy.ts +163 -57
- package/src/utils.ts +32 -0
package/src/utils.ts
CHANGED
|
@@ -23,3 +23,35 @@ export function capSentence(cap) {
|
|
|
23
23
|
can
|
|
24
24
|
)} your ${domain} actions, with access to ${formatList(pointers)}`;
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Escapes a string value for safe use in SurrealQL queries.
|
|
29
|
+
*
|
|
30
|
+
* @description
|
|
31
|
+
* Prevents SQL injection by properly escaping special characters in string values
|
|
32
|
+
* that will be interpolated into SurrealQL queries. This handles the most common
|
|
33
|
+
* special characters that could break SQL queries or enable injection attacks.
|
|
34
|
+
*
|
|
35
|
+
* Single quotes, backslashes, and other special characters are escaped using
|
|
36
|
+
* backslash notation, which is the standard escaping mechanism for SurrealQL.
|
|
37
|
+
*
|
|
38
|
+
* @param value - The string value to escape
|
|
39
|
+
* @returns The escaped string safe for SurrealQL interpolation (without surrounding quotes)
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const userInput = "user's input with 'quotes'";
|
|
44
|
+
* const escaped = escapeSurrealString(userInput);
|
|
45
|
+
* const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
|
|
46
|
+
* // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function escapeSurrealString(value: string): string {
|
|
50
|
+
return value
|
|
51
|
+
.replace(/\\/g, '\\\\') // Backslash -> \\
|
|
52
|
+
.replace(/'/g, "\\'") // Single quote -> \'
|
|
53
|
+
.replace(/"/g, '\\"') // Double quote -> \"
|
|
54
|
+
.replace(/\n/g, '\\n') // Newline -> \n
|
|
55
|
+
.replace(/\r/g, '\\r') // Carriage return -> \r
|
|
56
|
+
.replace(/\t/g, '\\t'); // Tab -> \t
|
|
57
|
+
}
|