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/dist/node.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var stream = require('stream');
4
4
  var module$1 = require('module');
5
5
 
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
6
7
  let decoder;
7
8
  try {
8
9
  decoder = new TextDecoder();
@@ -600,43 +601,49 @@ function readStringJS(length) {
600
601
  units.push(byte1);
601
602
  } else if ((byte1 & 0xe0) === 0xc0) {
602
603
  // 2 bytes
603
- const byte2 = src[position$1++] & 0x3f;
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
604
+ if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
605
+ units.push(0xFFFD);
608
606
  } else {
609
- units.push(codePoint);
607
+ const byte2 = src[position$1++] & 0x3f;
608
+ units.push(((byte1 & 0x1f) << 6) | byte2);
610
609
  }
611
610
  } else if ((byte1 & 0xf0) === 0xe0) {
612
611
  // 3 bytes
613
- const byte2 = src[position$1++] & 0x3f;
614
- const byte3 = src[position$1++] & 0x3f;
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
612
+ const byte2 = position$1 < end ? src[position$1] : 0;
613
+ if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
614
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
615
+ units.push(0xFFFD);
620
616
  } else {
621
- units.push(codePoint);
617
+ position$1++;
618
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
619
+ units.push(0xFFFD);
620
+ } else {
621
+ const byte3 = src[position$1++] & 0x3f;
622
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
623
+ }
622
624
  }
623
625
  } else if ((byte1 & 0xf8) === 0xf0) {
624
626
  // 4 bytes
625
- const byte2 = src[position$1++] & 0x3f;
626
- const byte3 = src[position$1++] & 0x3f;
627
- const byte4 = src[position$1++] & 0x3f;
628
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
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) {
634
- unit -= 0x10000;
635
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
636
- unit = 0xdc00 | (unit & 0x3ff);
637
- units.push(unit);
627
+ const byte2 = position$1 < end ? src[position$1] : 0;
628
+ if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
629
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
630
+ units.push(0xFFFD);
638
631
  } else {
639
- units.push(unit);
632
+ position$1++;
633
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
634
+ units.push(0xFFFD);
635
+ } else {
636
+ const byte3 = src[position$1++] & 0x3f;
637
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
638
+ units.push(0xFFFD);
639
+ } else {
640
+ const byte4 = src[position$1++] & 0x3f;
641
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
642
+ unit -= 0x10000;
643
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
644
+ units.push(0xdc00 | (unit & 0x3ff));
645
+ }
646
+ }
640
647
  }
641
648
  } else {
642
649
  units.push(0xFFFD); // replacement character for invalid lead byte
@@ -2621,7 +2628,7 @@ if (!nativeAccelerationDisabled) {
2621
2628
  if (typeof require == 'function')
2622
2629
  extractor = require('cbor-extract');
2623
2630
  else
2624
- extractor = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node.cjs', document.baseURI).href)))('cbor-extract');
2631
+ extractor = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node.cjs', document.baseURI).href)))('cbor-extract');
2625
2632
  if (extractor)
2626
2633
  setExtractor(extractor.extractStrings);
2627
2634
  } catch (error) {