msgpackr 1.10.0 → 1.10.1

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/index.js CHANGED
@@ -858,7 +858,7 @@
858
858
  return readFixedString(length)
859
859
  } else { // not cacheable, go back and do a standard read
860
860
  position$1--;
861
- return read().toString()
861
+ return asSafeString(read())
862
862
  }
863
863
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
864
864
  let entry = keyCache[key];
@@ -910,9 +910,15 @@
910
910
  return entry.string = readFixedString(length)
911
911
  }
912
912
 
913
+ function asSafeString(property) {
914
+ if (typeof property === 'string') return property;
915
+ if (typeof property === 'number') return property.toString();
916
+ throw new Error('Invalid property type for record', typeof property);
917
+ }
913
918
  // the registration of the record definition extension (as "r")
914
919
  const recordDefinition = (id, highByte) => {
915
- let structure = read().map(property => property.toString()); // ensure that all keys are strings and that the array is mutable
920
+ let structure = read().map(asSafeString); // ensure that all keys are strings and
921
+ // that the array is mutable
916
922
  let firstByte = id;
917
923
  if (highByte !== undefined) {
918
924
  id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
@@ -951,6 +957,7 @@
951
957
 
952
958
  currentExtensions[0x69] = (data) => {
953
959
  // id extension (for structured clones)
960
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
954
961
  let id = dataView.getUint32(position$1 - 4);
955
962
  if (!referenceMap)
956
963
  referenceMap = new Map();
@@ -974,6 +981,7 @@
974
981
 
975
982
  currentExtensions[0x70] = (data) => {
976
983
  // pointer extension (for structured clones)
984
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
977
985
  let id = dataView.getUint32(position$1 - 4);
978
986
  let refEntry = referenceMap.get(id);
979
987
  refEntry.used = true;