cbor-x 1.6.0 → 1.6.4
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/README.md +8 -7
- package/decode.js +26 -7
- package/dist/decode-no-eval.cjs +26 -7
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +37 -10
- 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 +37 -10
- 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 +37 -10
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +67 -11
- package/dist/test.js.map +1 -1
- package/encode.js +11 -3
- package/package.json +2 -2
package/dist/node.cjs
CHANGED
|
@@ -269,6 +269,7 @@ function read() {
|
|
|
269
269
|
}
|
|
270
270
|
token = dataView.getUint32(position$1);
|
|
271
271
|
position$1 += 4;
|
|
272
|
+
if (majorType === 1) return -1 - token; // can't safely use negation operator here
|
|
272
273
|
break
|
|
273
274
|
case 0x1b:
|
|
274
275
|
if (majorType == 7) {
|
|
@@ -283,8 +284,7 @@ function read() {
|
|
|
283
284
|
} else if (currentDecoder.int64AsNumber) {
|
|
284
285
|
token = dataView.getUint32(position$1) * 0x100000000;
|
|
285
286
|
token += dataView.getUint32(position$1 + 4);
|
|
286
|
-
} else
|
|
287
|
-
token = dataView.getBigUint64(position$1);
|
|
287
|
+
} else token = dataView.getBigUint64(position$1);
|
|
288
288
|
position$1 += 8;
|
|
289
289
|
break
|
|
290
290
|
case 0x1f:
|
|
@@ -601,26 +601,45 @@ function readStringJS(length) {
|
|
|
601
601
|
} else if ((byte1 & 0xe0) === 0xc0) {
|
|
602
602
|
// 2 bytes
|
|
603
603
|
const byte2 = src[position$1++] & 0x3f;
|
|
604
|
-
|
|
604
|
+
const codePoint = ((byte1 & 0x1f) << 6) | byte2;
|
|
605
|
+
// Reject overlong encoding: 2-byte sequences must encode values >= 0x80
|
|
606
|
+
if (codePoint < 0x80) {
|
|
607
|
+
units.push(0xFFFD); // replacement character
|
|
608
|
+
} else {
|
|
609
|
+
units.push(codePoint);
|
|
610
|
+
}
|
|
605
611
|
} else if ((byte1 & 0xf0) === 0xe0) {
|
|
606
612
|
// 3 bytes
|
|
607
613
|
const byte2 = src[position$1++] & 0x3f;
|
|
608
614
|
const byte3 = src[position$1++] & 0x3f;
|
|
609
|
-
|
|
615
|
+
const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
|
|
616
|
+
// Reject overlong encoding: 3-byte sequences must encode values >= 0x800
|
|
617
|
+
// Also reject surrogates (0xD800-0xDFFF)
|
|
618
|
+
if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
|
|
619
|
+
units.push(0xFFFD); // replacement character
|
|
620
|
+
} else {
|
|
621
|
+
units.push(codePoint);
|
|
622
|
+
}
|
|
610
623
|
} else if ((byte1 & 0xf8) === 0xf0) {
|
|
611
624
|
// 4 bytes
|
|
612
625
|
const byte2 = src[position$1++] & 0x3f;
|
|
613
626
|
const byte3 = src[position$1++] & 0x3f;
|
|
614
627
|
const byte4 = src[position$1++] & 0x3f;
|
|
615
628
|
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
|
616
|
-
|
|
629
|
+
// Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
|
|
630
|
+
// Also reject values > 0x10FFFF (maximum valid Unicode)
|
|
631
|
+
if (unit < 0x10000 || unit > 0x10FFFF) {
|
|
632
|
+
units.push(0xFFFD); // replacement character
|
|
633
|
+
} else if (unit > 0xffff) {
|
|
617
634
|
unit -= 0x10000;
|
|
618
635
|
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
619
636
|
unit = 0xdc00 | (unit & 0x3ff);
|
|
637
|
+
units.push(unit);
|
|
638
|
+
} else {
|
|
639
|
+
units.push(unit);
|
|
620
640
|
}
|
|
621
|
-
units.push(unit);
|
|
622
641
|
} else {
|
|
623
|
-
units.push(
|
|
642
|
+
units.push(0xFFFD); // replacement character for invalid lead byte
|
|
624
643
|
}
|
|
625
644
|
|
|
626
645
|
if (units.length >= 0x1000) {
|
|
@@ -1249,8 +1268,8 @@ class Encoder extends Decoder {
|
|
|
1249
1268
|
let structures;
|
|
1250
1269
|
let referenceMap;
|
|
1251
1270
|
options = options || {};
|
|
1252
|
-
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position
|
|
1253
|
-
return target.utf8Write(string, position,
|
|
1271
|
+
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1272
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
1254
1273
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1255
1274
|
function(string, position) {
|
|
1256
1275
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
@@ -1631,7 +1650,7 @@ class Encoder extends Decoder {
|
|
|
1631
1650
|
targetView.setUint32(position, value);
|
|
1632
1651
|
position += 4;
|
|
1633
1652
|
}
|
|
1634
|
-
} else if (!this.alwaysUseFloat && value >> 0 === value) { // negative integer
|
|
1653
|
+
} else if (!this.alwaysUseFloat && value >> 0 === value) { // negative integer, 31-bit or less
|
|
1635
1654
|
if (value >= -0x18) {
|
|
1636
1655
|
target[position++] = 0x1f - value;
|
|
1637
1656
|
} else if (value >= -0x100) {
|
|
@@ -1646,6 +1665,11 @@ class Encoder extends Decoder {
|
|
|
1646
1665
|
targetView.setUint32(position, ~value);
|
|
1647
1666
|
position += 4;
|
|
1648
1667
|
}
|
|
1668
|
+
} else if (!this.alwaysUseFloat && value < 0 && value >= -0x100000000 && Math.floor(value) === value) {
|
|
1669
|
+
// negative integer, 32-bit or less
|
|
1670
|
+
target[position++] = 0x3a;
|
|
1671
|
+
targetView.setUint32(position, -1 - value);
|
|
1672
|
+
position += 4;
|
|
1649
1673
|
} else {
|
|
1650
1674
|
let useFloat32;
|
|
1651
1675
|
if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
|
|
@@ -1687,6 +1711,9 @@ class Encoder extends Decoder {
|
|
|
1687
1711
|
}
|
|
1688
1712
|
let constructor = value.constructor;
|
|
1689
1713
|
if (constructor === Object) {
|
|
1714
|
+
if (this.skipFunction === true) {
|
|
1715
|
+
value = Object.fromEntries([...Object.keys(value).filter(x => typeof value[x] !== "function").map(x => [x, value[x]])]);
|
|
1716
|
+
}
|
|
1690
1717
|
writeObject(value);
|
|
1691
1718
|
} else if (constructor === Array) {
|
|
1692
1719
|
length = value.length;
|