@prairielearn/sanitize 2.0.18 → 2.0.20

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prairielearn/sanitize
2
2
 
3
+ ## 2.0.20
4
+
5
+ ### Patch Changes
6
+
7
+ - c72a4b8: Upgrade dependencies
8
+
9
+ ## 2.0.19
10
+
11
+ ### Patch Changes
12
+
13
+ - f571b40: Upgrade all JavaScript dependencies
14
+
3
15
  ## 2.0.18
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ export function sanitizeObject(value) {
37
37
  * @returns A string literal ready to match
38
38
  */
39
39
  export function escapeRegExp(str) {
40
- return str.replace(/[.*+\-?^${}()|[\]\\/]/g, '\\$&');
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.substring(0, maxLength) + '...[truncated]');
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,KA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AAO,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.replace(/[.*+\\-?^${}()|[\\]\\\\/]/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.substring(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"]}
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,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5C,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACjB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAS,CAAM,CAAC;IACrB,CAAC;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.18",
3
+ "version": "2.0.20",
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.17.0",
18
+ "@types/node": "^22.18.8",
19
19
  "@vitest/coverage-v8": "^3.2.4",
20
- "tsx": "^4.20.3",
21
- "typescript": "^5.9.2",
20
+ "tsx": "^4.20.6",
21
+ "typescript": "^5.9.3",
22
22
  "vitest": "^3.2.4"
23
23
  }
24
24
  }
package/src/index.ts CHANGED
@@ -34,7 +34,7 @@ export function sanitizeObject<T>(value: T): T {
34
34
  * @returns A string literal ready to match
35
35
  */
36
36
  export function escapeRegExp(str: string) {
37
- return str.replace(/[.*+\-?^${}()|[\]\\/]/g, '\\$&');
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.substring(0, maxLength) + '...[truncated]') as T;
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') {