seroval 1.6.6 → 1.6.7

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.
@@ -197,6 +197,7 @@ function deserializeReplacer(str) {
197
197
  }
198
198
  }
199
199
  function deserializeString(str) {
200
+ if (typeof str === "string" && !str.includes("\\")) return str;
200
201
  return str.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, deserializeReplacer);
201
202
  }
202
203
  //#endregion
@@ -1234,6 +1235,7 @@ function isValidSymbol(symbol) {
1234
1235
  //#endregion
1235
1236
  //#region src/core/context/deserializer.ts
1236
1237
  const DEFAULT_MAX_BASE64_LENGTH = 1e6;
1238
+ const MIN_NATIVE_BASE64_LENGTH = 512;
1237
1239
  const MAX_BIGINT_LENGTH = 1e4;
1238
1240
  const MAX_REGEXP_SOURCE_LENGTH = 2e4;
1239
1241
  function applyObjectFlag(obj, flag) {
@@ -1422,7 +1424,15 @@ function deserializeMap(ctx, depth, node) {
1422
1424
  function deserializeArrayBuffer(ctx, node) {
1423
1425
  if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
1424
1426
  if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
1425
- return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
1427
+ const source = deserializeString(node.s);
1428
+ let buffer;
1429
+ if (source.length < MIN_NATIVE_BASE64_LENGTH || typeof Buffer === "undefined") buffer = ARRAY_BUFFER_CONSTRUCTOR(source);
1430
+ else {
1431
+ const decoded = atob(source);
1432
+ buffer = new ArrayBuffer(decoded.length);
1433
+ Buffer.from(buffer).write(decoded, "latin1");
1434
+ }
1435
+ return assignIndexedValue$1(ctx, node.i, buffer);
1426
1436
  }
1427
1437
  function deserializeTypedArray(ctx, depth, node) {
1428
1438
  var _node$b;
@@ -1430,7 +1440,7 @@ function deserializeTypedArray(ctx, depth, node) {
1430
1440
  const source = deserialize$1(ctx, depth, node.f);
1431
1441
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1432
1442
  const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
1433
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1443
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1434
1444
  return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
1435
1445
  }
1436
1446
  function deserializeDataView(ctx, depth, node) {
@@ -1438,7 +1448,7 @@ function deserializeDataView(ctx, depth, node) {
1438
1448
  const source = deserialize$1(ctx, depth, node.f);
1439
1449
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1440
1450
  const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
1441
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1451
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1442
1452
  return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
1443
1453
  }
1444
1454
  function deserializeDictionary(ctx, depth, node, result) {
package/dist/dev/index.js CHANGED
@@ -196,6 +196,7 @@ function deserializeReplacer(str) {
196
196
  }
197
197
  }
198
198
  function deserializeString(str) {
199
+ if (typeof str === "string" && !str.includes("\\")) return str;
199
200
  return str.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, deserializeReplacer);
200
201
  }
201
202
  //#endregion
@@ -1233,6 +1234,7 @@ function isValidSymbol(symbol) {
1233
1234
  //#endregion
1234
1235
  //#region src/core/context/deserializer.ts
1235
1236
  const DEFAULT_MAX_BASE64_LENGTH = 1e6;
1237
+ const MIN_NATIVE_BASE64_LENGTH = 512;
1236
1238
  const MAX_BIGINT_LENGTH = 1e4;
1237
1239
  const MAX_REGEXP_SOURCE_LENGTH = 2e4;
1238
1240
  function applyObjectFlag(obj, flag) {
@@ -1421,7 +1423,15 @@ function deserializeMap(ctx, depth, node) {
1421
1423
  function deserializeArrayBuffer(ctx, node) {
1422
1424
  if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
1423
1425
  if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
1424
- return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
1426
+ const source = deserializeString(node.s);
1427
+ let buffer;
1428
+ if (source.length < MIN_NATIVE_BASE64_LENGTH || typeof Buffer === "undefined") buffer = ARRAY_BUFFER_CONSTRUCTOR(source);
1429
+ else {
1430
+ const decoded = atob(source);
1431
+ buffer = new ArrayBuffer(decoded.length);
1432
+ Buffer.from(buffer).write(decoded, "latin1");
1433
+ }
1434
+ return assignIndexedValue$1(ctx, node.i, buffer);
1425
1435
  }
1426
1436
  function deserializeTypedArray(ctx, depth, node) {
1427
1437
  var _node$b;
@@ -1429,7 +1439,7 @@ function deserializeTypedArray(ctx, depth, node) {
1429
1439
  const source = deserialize$1(ctx, depth, node.f);
1430
1440
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1431
1441
  const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
1432
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1442
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1433
1443
  return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
1434
1444
  }
1435
1445
  function deserializeDataView(ctx, depth, node) {
@@ -1437,7 +1447,7 @@ function deserializeDataView(ctx, depth, node) {
1437
1447
  const source = deserialize$1(ctx, depth, node.f);
1438
1448
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1439
1449
  const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
1440
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1450
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1441
1451
  return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
1442
1452
  }
1443
1453
  function deserializeDictionary(ctx, depth, node, result) {
package/dist/index.cjs CHANGED
@@ -197,6 +197,7 @@ function deserializeReplacer(str) {
197
197
  }
198
198
  }
199
199
  function deserializeString(str) {
200
+ if (typeof str === "string" && !str.includes("\\")) return str;
200
201
  return str.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, deserializeReplacer);
201
202
  }
202
203
  //#endregion
@@ -1227,6 +1228,7 @@ function isValidSymbol(symbol) {
1227
1228
  //#endregion
1228
1229
  //#region src/core/context/deserializer.ts
1229
1230
  const DEFAULT_MAX_BASE64_LENGTH = 1e6;
1231
+ const MIN_NATIVE_BASE64_LENGTH = 512;
1230
1232
  const MAX_BIGINT_LENGTH = 1e4;
1231
1233
  const MAX_REGEXP_SOURCE_LENGTH = 2e4;
1232
1234
  function applyObjectFlag(obj, flag) {
@@ -1415,7 +1417,15 @@ function deserializeMap(ctx, depth, node) {
1415
1417
  function deserializeArrayBuffer(ctx, node) {
1416
1418
  if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
1417
1419
  if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
1418
- return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
1420
+ const source = deserializeString(node.s);
1421
+ let buffer;
1422
+ if (source.length < MIN_NATIVE_BASE64_LENGTH || typeof Buffer === "undefined") buffer = ARRAY_BUFFER_CONSTRUCTOR(source);
1423
+ else {
1424
+ const decoded = atob(source);
1425
+ buffer = new ArrayBuffer(decoded.length);
1426
+ Buffer.from(buffer).write(decoded, "latin1");
1427
+ }
1428
+ return assignIndexedValue$1(ctx, node.i, buffer);
1419
1429
  }
1420
1430
  function deserializeTypedArray(ctx, depth, node) {
1421
1431
  var _node$b;
@@ -1423,7 +1433,7 @@ function deserializeTypedArray(ctx, depth, node) {
1423
1433
  const source = deserialize$1(ctx, depth, node.f);
1424
1434
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1425
1435
  const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
1426
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1436
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1427
1437
  return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
1428
1438
  }
1429
1439
  function deserializeDataView(ctx, depth, node) {
@@ -1431,7 +1441,7 @@ function deserializeDataView(ctx, depth, node) {
1431
1441
  const source = deserialize$1(ctx, depth, node.f);
1432
1442
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1433
1443
  const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
1434
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1444
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1435
1445
  return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
1436
1446
  }
1437
1447
  function deserializeDictionary(ctx, depth, node, result) {
package/dist/index.js CHANGED
@@ -196,6 +196,7 @@ function deserializeReplacer(str) {
196
196
  }
197
197
  }
198
198
  function deserializeString(str) {
199
+ if (typeof str === "string" && !str.includes("\\")) return str;
199
200
  return str.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, deserializeReplacer);
200
201
  }
201
202
  //#endregion
@@ -1226,6 +1227,7 @@ function isValidSymbol(symbol) {
1226
1227
  //#endregion
1227
1228
  //#region src/core/context/deserializer.ts
1228
1229
  const DEFAULT_MAX_BASE64_LENGTH = 1e6;
1230
+ const MIN_NATIVE_BASE64_LENGTH = 512;
1229
1231
  const MAX_BIGINT_LENGTH = 1e4;
1230
1232
  const MAX_REGEXP_SOURCE_LENGTH = 2e4;
1231
1233
  function applyObjectFlag(obj, flag) {
@@ -1414,7 +1416,15 @@ function deserializeMap(ctx, depth, node) {
1414
1416
  function deserializeArrayBuffer(ctx, node) {
1415
1417
  if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
1416
1418
  if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
1417
- return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
1419
+ const source = deserializeString(node.s);
1420
+ let buffer;
1421
+ if (source.length < MIN_NATIVE_BASE64_LENGTH || typeof Buffer === "undefined") buffer = ARRAY_BUFFER_CONSTRUCTOR(source);
1422
+ else {
1423
+ const decoded = atob(source);
1424
+ buffer = new ArrayBuffer(decoded.length);
1425
+ Buffer.from(buffer).write(decoded, "latin1");
1426
+ }
1427
+ return assignIndexedValue$1(ctx, node.i, buffer);
1418
1428
  }
1419
1429
  function deserializeTypedArray(ctx, depth, node) {
1420
1430
  var _node$b;
@@ -1422,7 +1432,7 @@ function deserializeTypedArray(ctx, depth, node) {
1422
1432
  const source = deserialize$1(ctx, depth, node.f);
1423
1433
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1424
1434
  const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
1425
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1435
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1426
1436
  return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
1427
1437
  }
1428
1438
  function deserializeDataView(ctx, depth, node) {
@@ -1430,7 +1440,7 @@ function deserializeDataView(ctx, depth, node) {
1430
1440
  const source = deserialize$1(ctx, depth, node.f);
1431
1441
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1432
1442
  const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
1433
- if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1443
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1434
1444
  return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
1435
1445
  }
1436
1446
  function deserializeDictionary(ctx, depth, node, result) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "seroval",
3
3
  "type": "module",
4
- "version": "1.6.6",
4
+ "version": "1.6.7",
5
5
  "files": [
6
6
  "dist"
7
7
  ],