playsocketjs 5.2.0 → 5.2.1
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/package.json
CHANGED
|
@@ -110,7 +110,7 @@ export default class CRDTManager {
|
|
|
110
110
|
importPropertyUpdate(update) {
|
|
111
111
|
try {
|
|
112
112
|
const { key, operation: rawOperation, vectorClock } = update;
|
|
113
|
-
const operation = /** @type {Operation} */ (this.#
|
|
113
|
+
const operation = /** @type {Operation} */ (this.#normalizeAndCopy(rawOperation));
|
|
114
114
|
if (this.#debug) console.log(CONSOLE_PREFIX + "Importing update:", update); // Debug
|
|
115
115
|
|
|
116
116
|
// Check key limit to safeguard against too many keys
|
|
@@ -183,9 +183,9 @@ export default class CRDTManager {
|
|
|
183
183
|
*/
|
|
184
184
|
updateProperty(key, type, value, secondValue) {
|
|
185
185
|
try {
|
|
186
|
-
//
|
|
187
|
-
value = this.#
|
|
188
|
-
secondValue = this.#
|
|
186
|
+
// Normalize inputs
|
|
187
|
+
value = this.#normalizeAndCopy(value);
|
|
188
|
+
secondValue = this.#normalizeAndCopy(secondValue);
|
|
189
189
|
|
|
190
190
|
// Debug log
|
|
191
191
|
if (this.#debug) console.log(CONSOLE_PREFIX + `Updating property with key ${key}, type ${type}, value ${value} and secondValue ${secondValue}`);
|
|
@@ -431,20 +431,15 @@ export default class CRDTManager {
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
/**
|
|
434
|
-
*
|
|
435
|
-
* @param {*} value - Value to
|
|
436
|
-
* @returns {*}
|
|
434
|
+
* Enforce size limit, normalize undefined to null, and return deep copy
|
|
435
|
+
* @param {*} value - Value to normalize
|
|
436
|
+
* @returns {*} Normalized value
|
|
437
437
|
*/
|
|
438
|
-
#
|
|
439
|
-
if (value === undefined) return null;
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (jsonString?.length > 50000) throw new Error("Value too large"); // 50KB limit
|
|
444
|
-
|
|
445
|
-
if (typeof value === "string") return (value.includes("<") || value.includes(">")) ? value.replace(/[<>]/g, "") : value;
|
|
446
|
-
if (Array.isArray(value)) return Array.from(value, item => this.#sanitizeValue(item));
|
|
447
|
-
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.#sanitizeValue(v)]));
|
|
438
|
+
#normalizeAndCopy(value) {
|
|
439
|
+
if (value === undefined) return null;
|
|
440
|
+
if (JSON.stringify(value)?.length > 50_000) throw new Error("Value too large"); // 50KB limit
|
|
441
|
+
if (Array.isArray(value)) return Array.from(value, item => this.#normalizeAndCopy(item));
|
|
442
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.#normalizeAndCopy(v)]));
|
|
448
443
|
return value;
|
|
449
444
|
}
|
|
450
445
|
|