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/test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
(function (stream, module, chai, fs) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
4
5
|
let decoder;
|
|
5
6
|
try {
|
|
6
7
|
decoder = new TextDecoder();
|
|
@@ -595,43 +596,49 @@
|
|
|
595
596
|
units.push(byte1);
|
|
596
597
|
} else if ((byte1 & 0xe0) === 0xc0) {
|
|
597
598
|
// 2 bytes
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
// Reject overlong encoding: 2-byte sequences must encode values >= 0x80
|
|
601
|
-
if (codePoint < 0x80) {
|
|
602
|
-
units.push(0xFFFD); // replacement character
|
|
599
|
+
if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
600
|
+
units.push(0xFFFD);
|
|
603
601
|
} else {
|
|
604
|
-
|
|
602
|
+
const byte2 = src[position$1++] & 0x3f;
|
|
603
|
+
units.push(((byte1 & 0x1f) << 6) | byte2);
|
|
605
604
|
}
|
|
606
605
|
} else if ((byte1 & 0xf0) === 0xe0) {
|
|
607
606
|
// 3 bytes
|
|
608
|
-
const byte2 = src[position$1
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
// Also reject surrogates (0xD800-0xDFFF)
|
|
613
|
-
if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
|
|
614
|
-
units.push(0xFFFD); // replacement character
|
|
607
|
+
const byte2 = position$1 < end ? src[position$1] : 0;
|
|
608
|
+
if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
|
|
609
|
+
(byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
|
|
610
|
+
units.push(0xFFFD);
|
|
615
611
|
} else {
|
|
616
|
-
|
|
612
|
+
position$1++;
|
|
613
|
+
if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
614
|
+
units.push(0xFFFD);
|
|
615
|
+
} else {
|
|
616
|
+
const byte3 = src[position$1++] & 0x3f;
|
|
617
|
+
units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
|
|
618
|
+
}
|
|
617
619
|
}
|
|
618
620
|
} else if ((byte1 & 0xf8) === 0xf0) {
|
|
619
621
|
// 4 bytes
|
|
620
|
-
const byte2 = src[position$1
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
// Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
|
|
625
|
-
// Also reject values > 0x10FFFF (maximum valid Unicode)
|
|
626
|
-
if (unit < 0x10000 || unit > 0x10FFFF) {
|
|
627
|
-
units.push(0xFFFD); // replacement character
|
|
628
|
-
} else if (unit > 0xffff) {
|
|
629
|
-
unit -= 0x10000;
|
|
630
|
-
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
631
|
-
unit = 0xdc00 | (unit & 0x3ff);
|
|
632
|
-
units.push(unit);
|
|
622
|
+
const byte2 = position$1 < end ? src[position$1] : 0;
|
|
623
|
+
if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
|
|
624
|
+
(byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
|
|
625
|
+
units.push(0xFFFD);
|
|
633
626
|
} else {
|
|
634
|
-
|
|
627
|
+
position$1++;
|
|
628
|
+
if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
629
|
+
units.push(0xFFFD);
|
|
630
|
+
} else {
|
|
631
|
+
const byte3 = src[position$1++] & 0x3f;
|
|
632
|
+
if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
|
|
633
|
+
units.push(0xFFFD);
|
|
634
|
+
} else {
|
|
635
|
+
const byte4 = src[position$1++] & 0x3f;
|
|
636
|
+
let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
|
|
637
|
+
unit -= 0x10000;
|
|
638
|
+
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
639
|
+
units.push(0xdc00 | (unit & 0x3ff));
|
|
640
|
+
}
|
|
641
|
+
}
|
|
635
642
|
}
|
|
636
643
|
} else {
|
|
637
644
|
units.push(0xFFFD); // replacement character for invalid lead byte
|
|
@@ -2462,7 +2469,7 @@
|
|
|
2462
2469
|
if (typeof require == 'function')
|
|
2463
2470
|
extractor = require('cbor-extract');
|
|
2464
2471
|
else
|
|
2465
|
-
extractor = module.createRequire((
|
|
2472
|
+
extractor = module.createRequire((_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('test.js', document.baseURI).href))('cbor-extract');
|
|
2466
2473
|
if (extractor)
|
|
2467
2474
|
setExtractor(extractor.extractStrings);
|
|
2468
2475
|
} catch (error) {
|
|
@@ -2470,7 +2477,7 @@
|
|
|
2470
2477
|
}
|
|
2471
2478
|
}
|
|
2472
2479
|
|
|
2473
|
-
const sampleData = JSON.parse(fs.readFileSync(new URL('./example4.json', (
|
|
2480
|
+
const sampleData = JSON.parse(fs.readFileSync(new URL('./example4.json', (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('test.js', document.baseURI).href))));
|
|
2474
2481
|
|
|
2475
2482
|
const senmlData = [
|
|
2476
2483
|
{ bn: '/3303/0/5700', bt: 1278887, v: 35.5 },
|