@everymatrix/nuts-inbox-widget 1.90.16 → 1.90.18
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.
|
@@ -2524,12 +2524,13 @@ class Encoder {
|
|
|
2524
2524
|
class Decoder extends Emitter {
|
|
2525
2525
|
/**
|
|
2526
2526
|
* Decoder constructor
|
|
2527
|
-
*
|
|
2528
|
-
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
2529
2527
|
*/
|
|
2530
|
-
constructor(
|
|
2528
|
+
constructor(opts) {
|
|
2531
2529
|
super();
|
|
2532
|
-
this.
|
|
2530
|
+
this.opts = Object.assign({
|
|
2531
|
+
reviver: undefined,
|
|
2532
|
+
maxAttachments: 10,
|
|
2533
|
+
}, typeof opts === "function" ? { reviver: opts } : opts);
|
|
2533
2534
|
}
|
|
2534
2535
|
/**
|
|
2535
2536
|
* Decodes an encoded packet string into packet JSON.
|
|
@@ -2600,7 +2601,14 @@ class Decoder extends Emitter {
|
|
|
2600
2601
|
if (buf != Number(buf) || str.charAt(i) !== "-") {
|
|
2601
2602
|
throw new Error("Illegal attachments");
|
|
2602
2603
|
}
|
|
2603
|
-
|
|
2604
|
+
const n = Number(buf);
|
|
2605
|
+
if (!isInteger(n) || n < 0) {
|
|
2606
|
+
throw new Error("Illegal attachments");
|
|
2607
|
+
}
|
|
2608
|
+
else if (n > this.opts.maxAttachments) {
|
|
2609
|
+
throw new Error("too many attachments");
|
|
2610
|
+
}
|
|
2611
|
+
p.attachments = n;
|
|
2604
2612
|
}
|
|
2605
2613
|
// look up namespace (if any)
|
|
2606
2614
|
if ("/" === str.charAt(i + 1)) {
|
|
@@ -2646,7 +2654,7 @@ class Decoder extends Emitter {
|
|
|
2646
2654
|
}
|
|
2647
2655
|
tryParse(str) {
|
|
2648
2656
|
try {
|
|
2649
|
-
return JSON.parse(str, this.reviver);
|
|
2657
|
+
return JSON.parse(str, this.opts.reviver);
|
|
2650
2658
|
}
|
|
2651
2659
|
catch (e) {
|
|
2652
2660
|
return false;
|
|
@@ -2520,12 +2520,13 @@ class Encoder {
|
|
|
2520
2520
|
class Decoder extends Emitter {
|
|
2521
2521
|
/**
|
|
2522
2522
|
* Decoder constructor
|
|
2523
|
-
*
|
|
2524
|
-
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
2525
2523
|
*/
|
|
2526
|
-
constructor(
|
|
2524
|
+
constructor(opts) {
|
|
2527
2525
|
super();
|
|
2528
|
-
this.
|
|
2526
|
+
this.opts = Object.assign({
|
|
2527
|
+
reviver: undefined,
|
|
2528
|
+
maxAttachments: 10,
|
|
2529
|
+
}, typeof opts === "function" ? { reviver: opts } : opts);
|
|
2529
2530
|
}
|
|
2530
2531
|
/**
|
|
2531
2532
|
* Decodes an encoded packet string into packet JSON.
|
|
@@ -2596,7 +2597,14 @@ class Decoder extends Emitter {
|
|
|
2596
2597
|
if (buf != Number(buf) || str.charAt(i) !== "-") {
|
|
2597
2598
|
throw new Error("Illegal attachments");
|
|
2598
2599
|
}
|
|
2599
|
-
|
|
2600
|
+
const n = Number(buf);
|
|
2601
|
+
if (!isInteger(n) || n < 0) {
|
|
2602
|
+
throw new Error("Illegal attachments");
|
|
2603
|
+
}
|
|
2604
|
+
else if (n > this.opts.maxAttachments) {
|
|
2605
|
+
throw new Error("too many attachments");
|
|
2606
|
+
}
|
|
2607
|
+
p.attachments = n;
|
|
2600
2608
|
}
|
|
2601
2609
|
// look up namespace (if any)
|
|
2602
2610
|
if ("/" === str.charAt(i + 1)) {
|
|
@@ -2642,7 +2650,7 @@ class Decoder extends Emitter {
|
|
|
2642
2650
|
}
|
|
2643
2651
|
tryParse(str) {
|
|
2644
2652
|
try {
|
|
2645
|
-
return JSON.parse(str, this.reviver);
|
|
2653
|
+
return JSON.parse(str, this.opts.reviver);
|
|
2646
2654
|
}
|
|
2647
2655
|
catch (e) {
|
|
2648
2656
|
return false;
|