@prairielearn/sanitize 2.0.17 → 2.0.19
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +4 -4
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* provided object.
|
|
5
5
|
*
|
|
6
6
|
* @param value The object to be sanitized.
|
|
7
|
-
* @
|
|
7
|
+
* @returns The sanitized object.
|
|
8
8
|
*/
|
|
9
9
|
export declare function sanitizeObject<T>(value: T): T;
|
|
10
10
|
/**
|
|
@@ -12,7 +12,7 @@ export declare function sanitizeObject<T>(value: T): T;
|
|
|
12
12
|
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters
|
|
13
13
|
*
|
|
14
14
|
* @param str A literal string to act as a match for RegExp objects
|
|
15
|
-
* @
|
|
15
|
+
* @returns A string literal ready to match
|
|
16
16
|
*/
|
|
17
17
|
export declare function escapeRegExp(str: string): string;
|
|
18
18
|
/**
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* provided object.
|
|
5
5
|
*
|
|
6
6
|
* @param value The object to be sanitized.
|
|
7
|
-
* @
|
|
7
|
+
* @returns The sanitized object.
|
|
8
8
|
*/
|
|
9
9
|
export function sanitizeObject(value) {
|
|
10
10
|
if (value === null) {
|
|
@@ -34,10 +34,10 @@ export function sanitizeObject(value) {
|
|
|
34
34
|
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters
|
|
35
35
|
*
|
|
36
36
|
* @param str A literal string to act as a match for RegExp objects
|
|
37
|
-
* @
|
|
37
|
+
* @returns A string literal ready to match
|
|
38
38
|
*/
|
|
39
39
|
export function escapeRegExp(str) {
|
|
40
|
-
return str.
|
|
40
|
+
return str.replaceAll(/[.*+\-?^${}()|[\]\\/]/g, '\\$&');
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Recursively truncates all strings in a value to a maximum length.
|
|
@@ -50,7 +50,7 @@ export function recursivelyTruncateStrings(value, maxLength) {
|
|
|
50
50
|
if (value.length <= maxLength) {
|
|
51
51
|
return value;
|
|
52
52
|
}
|
|
53
|
-
return (value.
|
|
53
|
+
return (value.slice(0, maxLength) + '...[truncated]');
|
|
54
54
|
}
|
|
55
55
|
else if (Array.isArray(value)) {
|
|
56
56
|
return value.map((value) => recursivelyTruncateStrings(value, maxLength));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAI,KAAQ;IACxC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAS,CAAC;IACnB,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,GAAG,CAAC,cAAc,CAAM,CAAC;IACxC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAM,CAAC;IACpD,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC3D,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QACH,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,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AC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,UAAU,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAI,KAAQ,EAAE,SAAiB;IACvE,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAS,CAAC;IACnB,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAM,CAAC;IAC7D,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,0BAA0B,CAAC,KAAK,EAAE,SAAS,CAAC,CAAM,CAAC;IACjF,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACxD,GAAG,CAAC,GAAG,CAAC,GAAG,0BAA0B,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACxD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAS,CAAM,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["/**\n * Recursively traverse an object and replace null bytes (\\u0000) with the\n * literal string \"\\u0000\". This produces a new object and does not modify the\n * provided object.\n *\n * @param value The object to be sanitized.\n * @returns The sanitized object.\n */\nexport function sanitizeObject<T>(value: T): T {\n if (value === null) {\n return null as T;\n } else if (Array.isArray(value)) {\n return value.map(sanitizeObject) as T;\n } else if (typeof value === 'string') {\n return value.replaceAll('\\u0000', '\\\\u0000') as T;\n } else if (typeof value === 'object') {\n const sanitized = Object.entries(value).map(([key, value]) => {\n return [key, sanitizeObject(value)];\n });\n return sanitized.reduce((acc, [key, value]) => {\n acc[key] = value;\n return acc;\n }, {} as any) as T;\n } else {\n return value;\n }\n}\n\n/**\n * Escape special characters in a RegExp string\n * Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters\n *\n * @param str A literal string to act as a match for RegExp objects\n * @returns A string literal ready to match\n */\nexport function escapeRegExp(str: string) {\n return str.replaceAll(/[.*+\\-?^${}()|[\\]\\\\/]/g, '\\\\$&');\n}\n\n/**\n * Recursively truncates all strings in a value to a maximum length.\n */\nexport function recursivelyTruncateStrings<T>(value: T, maxLength: number): T {\n if (value === null) {\n return null as T;\n } else if (typeof value === 'string') {\n if (value.length <= maxLength) {\n return value;\n }\n return (value.slice(0, maxLength) + '...[truncated]') as T;\n } else if (Array.isArray(value)) {\n return value.map((value) => recursivelyTruncateStrings(value, maxLength)) as T;\n } else if (typeof value === 'object') {\n return Object.entries(value).reduce((acc, [key, value]) => {\n acc[key] = recursivelyTruncateStrings(value, maxLength);\n return acc;\n }, {} as any) as T;\n } else {\n return value;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prairielearn/sanitize",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@prairielearn/tsconfig": "^0.0.0",
|
|
18
|
-
"@types/node": "^22.
|
|
18
|
+
"@types/node": "^22.18.0",
|
|
19
19
|
"@vitest/coverage-v8": "^3.2.4",
|
|
20
|
-
"tsx": "^4.20.
|
|
21
|
-
"typescript": "^5.
|
|
20
|
+
"tsx": "^4.20.5",
|
|
21
|
+
"typescript": "^5.9.2",
|
|
22
22
|
"vitest": "^3.2.4"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* provided object.
|
|
5
5
|
*
|
|
6
6
|
* @param value The object to be sanitized.
|
|
7
|
-
* @
|
|
7
|
+
* @returns The sanitized object.
|
|
8
8
|
*/
|
|
9
9
|
export function sanitizeObject<T>(value: T): T {
|
|
10
10
|
if (value === null) {
|
|
@@ -31,10 +31,10 @@ export function sanitizeObject<T>(value: T): T {
|
|
|
31
31
|
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters
|
|
32
32
|
*
|
|
33
33
|
* @param str A literal string to act as a match for RegExp objects
|
|
34
|
-
* @
|
|
34
|
+
* @returns A string literal ready to match
|
|
35
35
|
*/
|
|
36
36
|
export function escapeRegExp(str: string) {
|
|
37
|
-
return str.
|
|
37
|
+
return str.replaceAll(/[.*+\-?^${}()|[\]\\/]/g, '\\$&');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -47,7 +47,7 @@ export function recursivelyTruncateStrings<T>(value: T, maxLength: number): T {
|
|
|
47
47
|
if (value.length <= maxLength) {
|
|
48
48
|
return value;
|
|
49
49
|
}
|
|
50
|
-
return (value.
|
|
50
|
+
return (value.slice(0, maxLength) + '...[truncated]') as T;
|
|
51
51
|
} else if (Array.isArray(value)) {
|
|
52
52
|
return value.map((value) => recursivelyTruncateStrings(value, maxLength)) as T;
|
|
53
53
|
} else if (typeof value === 'object') {
|