cbor-x 1.6.4 → 1.6.5
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/decode.js +34 -28
- package/dist/decode-no-eval.cjs +34 -28
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +34 -28
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +34 -28
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +36 -29
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +37 -30
- package/dist/test.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -560,43 +560,49 @@
|
|
|
560
560
|
units.push(byte1);
|
|
561
561
|
} else if ((byte1 & 0xe0) === 0xc0) {
|
|
562
562
|
// 2 bytes
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
// Reject overlong encoding: 2-byte sequences must encode values >= 0x80
|
|
566
|
-
if (codePoint < 0x80) {
|
|
567
|
-
units.push(0xFFFD); // replacement character
|
|
563
|
+
if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
564
|
+
units.push(0xFFFD);
|
|
568
565
|
} else {
|
|
569
|
-
|
|
566
|
+
const byte2 = src[position$1++] & 0x3f;
|
|
567
|
+
units.push(((byte1 & 0x1f) << 6) | byte2);
|
|
570
568
|
}
|
|
571
569
|
} else if ((byte1 & 0xf0) === 0xe0) {
|
|
572
570
|
// 3 bytes
|
|
573
|
-
const byte2 = src[position$1
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
// Also reject surrogates (0xD800-0xDFFF)
|
|
578
|
-
if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
|
|
579
|
-
units.push(0xFFFD); // replacement character
|
|
571
|
+
const byte2 = position$1 < end ? src[position$1] : 0;
|
|
572
|
+
if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
|
|
573
|
+
(byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
|
|
574
|
+
units.push(0xFFFD);
|
|
580
575
|
} else {
|
|
581
|
-
|
|
576
|
+
position$1++;
|
|
577
|
+
if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
578
|
+
units.push(0xFFFD);
|
|
579
|
+
} else {
|
|
580
|
+
const byte3 = src[position$1++] & 0x3f;
|
|
581
|
+
units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
|
|
582
|
+
}
|
|
582
583
|
}
|
|
583
584
|
} else if ((byte1 & 0xf8) === 0xf0) {
|
|
584
585
|
// 4 bytes
|
|
585
|
-
const byte2 = src[position$1
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
// Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
|
|
590
|
-
// Also reject values > 0x10FFFF (maximum valid Unicode)
|
|
591
|
-
if (unit < 0x10000 || unit > 0x10FFFF) {
|
|
592
|
-
units.push(0xFFFD); // replacement character
|
|
593
|
-
} else if (unit > 0xffff) {
|
|
594
|
-
unit -= 0x10000;
|
|
595
|
-
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
596
|
-
unit = 0xdc00 | (unit & 0x3ff);
|
|
597
|
-
units.push(unit);
|
|
586
|
+
const byte2 = position$1 < end ? src[position$1] : 0;
|
|
587
|
+
if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
|
|
588
|
+
(byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
|
|
589
|
+
units.push(0xFFFD);
|
|
598
590
|
} else {
|
|
599
|
-
|
|
591
|
+
position$1++;
|
|
592
|
+
if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
593
|
+
units.push(0xFFFD);
|
|
594
|
+
} else {
|
|
595
|
+
const byte3 = src[position$1++] & 0x3f;
|
|
596
|
+
if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
597
|
+
units.push(0xFFFD);
|
|
598
|
+
} else {
|
|
599
|
+
const byte4 = src[position$1++] & 0x3f;
|
|
600
|
+
let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
|
|
601
|
+
unit -= 0x10000;
|
|
602
|
+
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
603
|
+
units.push(0xdc00 | (unit & 0x3ff));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
600
606
|
}
|
|
601
607
|
} else {
|
|
602
608
|
units.push(0xFFFD); // replacement character for invalid lead byte
|