Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
3
Maintainers
5
Versions
162
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.5.2 to 4.5.3

lib/error.js

2

bower.json

@@ -25,3 +25,3 @@ {

],
"version": "4.5.2"
"version": "4.5.3"
}

@@ -23,2 +23,6 @@ import { Buffer } from 'buffer';

static readonly SUBTYPE_MD5 = 5;
/** Encrypted BSON type */
static readonly SUBTYPE_ENCRYPTED = 6;
/** Column BSON type */
static readonly SUBTYPE_COLUMN = 7;
/** User BSON type */

@@ -116,6 +120,10 @@ static readonly SUBTYPE_USER_DEFINED = 128;

deserializeStream: typeof deserializeStream;
BSONError: typeof BSONError;
BSONTypeError: typeof BSONTypeError;
};
export default BSON;
/* Excluded from this release type: BSON_BINARY_SUBTYPE_BYTE_ARRAY */
/* Excluded from this release type: BSON_BINARY_SUBTYPE_COLUMN */
/* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
/* Excluded from this release type: BSON_BINARY_SUBTYPE_ENCRYPTED */
/* Excluded from this release type: BSON_BINARY_SUBTYPE_FUNCTION */

@@ -151,2 +159,6 @@ /* Excluded from this release type: BSON_BINARY_SUBTYPE_MD5 */

/* Excluded from this release type: BSON_INT64_MIN */
/** @public */
export declare class BSONError extends Error {
readonly name: string;
}
/**

@@ -200,2 +212,6 @@ * A class representation of the BSON RegExp type.

}
/** @public */
export declare class BSONTypeError extends TypeError {
readonly name: string;
}
/**

@@ -202,0 +218,0 @@ * Calculate the bson size for a passed in Javascript object.

@@ -8,2 +8,3 @@ "use strict";

var uuid_1 = require("./uuid");
var error_1 = require("./error");
/**

@@ -26,3 +27,3 @@ * A class representation of the BSON Binary type.

!Array.isArray(buffer)) {
throw new TypeError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
throw new error_1.BSONTypeError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
}

@@ -59,6 +60,6 @@ this.sub_type = subType !== null && subType !== void 0 ? subType : Binary.BSON_BINARY_SUBTYPE_DEFAULT;

if (typeof byteValue === 'string' && byteValue.length !== 1) {
throw new TypeError('only accepts single character String');
throw new error_1.BSONTypeError('only accepts single character String');
}
else if (typeof byteValue !== 'number' && byteValue.length !== 1)
throw new TypeError('only accepts single character Uint8Array or Array');
throw new error_1.BSONTypeError('only accepts single character Uint8Array or Array');
// Decode the byte value once

@@ -76,3 +77,3 @@ var decodedByte;

if (decodedByte < 0 || decodedByte > 255) {
throw new TypeError('only accepts number in a valid unsigned byte range 0-255');
throw new error_1.BSONTypeError('only accepts number in a valid unsigned byte range 0-255');
}

@@ -177,3 +178,3 @@ if (this.buffer.length > this.position) {

}
throw new Error("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
throw new error_1.BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
};

@@ -202,3 +203,3 @@ /** @internal */

if (!data) {
throw new TypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
throw new error_1.BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
}

@@ -234,2 +235,6 @@ return new Binary(data, type);

Binary.SUBTYPE_MD5 = 5;
/** Encrypted BSON type */
Binary.SUBTYPE_ENCRYPTED = 6;
/** Column BSON type */
Binary.SUBTYPE_COLUMN = 7;
/** User BSON type */

@@ -236,0 +241,0 @@ Binary.SUBTYPE_USER_DEFINED = 128;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectID = exports.Decimal128 = exports.BSONRegExp = exports.MaxKey = exports.MinKey = exports.Int32 = exports.Double = exports.Timestamp = exports.Long = exports.UUID = exports.ObjectId = exports.Binary = exports.DBRef = exports.BSONSymbol = exports.Map = exports.Code = exports.LongWithoutOverridesClass = exports.EJSON = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_STRING = exports.BSON_DATA_REGEXP = exports.BSON_DATA_OID = exports.BSON_DATA_OBJECT = exports.BSON_DATA_NUMBER = exports.BSON_DATA_NULL = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_LONG = exports.BSON_DATA_INT = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_DATE = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_CODE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = void 0;
exports.deserializeStream = exports.calculateObjectSize = exports.deserialize = exports.serializeWithBufferAndIndex = exports.serialize = exports.setInternalBufferSize = void 0;
exports.BSONRegExp = exports.MaxKey = exports.MinKey = exports.Int32 = exports.Double = exports.Timestamp = exports.Long = exports.UUID = exports.ObjectId = exports.Binary = exports.DBRef = exports.BSONSymbol = exports.Map = exports.Code = exports.LongWithoutOverridesClass = exports.EJSON = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_STRING = exports.BSON_DATA_REGEXP = exports.BSON_DATA_OID = exports.BSON_DATA_OBJECT = exports.BSON_DATA_NUMBER = exports.BSON_DATA_NULL = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_LONG = exports.BSON_DATA_INT = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_DATE = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_CODE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_BINARY_SUBTYPE_COLUMN = exports.BSON_BINARY_SUBTYPE_ENCRYPTED = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = void 0;
exports.deserializeStream = exports.calculateObjectSize = exports.deserialize = exports.serializeWithBufferAndIndex = exports.serialize = exports.setInternalBufferSize = exports.BSONTypeError = exports.BSONError = exports.ObjectID = exports.Decimal128 = void 0;
var buffer_1 = require("buffer");

@@ -31,2 +31,3 @@ var binary_1 = require("./binary");

Object.defineProperty(exports, "ObjectID", { enumerable: true, get: function () { return objectid_1.ObjectId; } });
var error_1 = require("./error");
var calculate_size_1 = require("./parser/calculate_size");

@@ -52,2 +53,4 @@ // Parts of the parser

Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID_NEW", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_UUID_NEW; } });
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_ENCRYPTED", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_ENCRYPTED; } });
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_COLUMN", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_COLUMN; } });
Object.defineProperty(exports, "BSON_DATA_ARRAY", { enumerable: true, get: function () { return constants_1.BSON_DATA_ARRAY; } });

@@ -82,2 +85,5 @@ Object.defineProperty(exports, "BSON_DATA_BINARY", { enumerable: true, get: function () { return constants_1.BSON_DATA_BINARY; } });

Object.defineProperty(exports, "LongWithoutOverridesClass", { enumerable: true, get: function () { return timestamp_2.LongWithoutOverridesClass; } });
var error_2 = require("./error");
Object.defineProperty(exports, "BSONError", { enumerable: true, get: function () { return error_2.BSONError; } });
Object.defineProperty(exports, "BSONTypeError", { enumerable: true, get: function () { return error_2.BSONTypeError; } });
/** @internal */

@@ -244,5 +250,7 @@ // Default Max Size

calculateObjectSize: calculateObjectSize,
deserializeStream: deserializeStream
deserializeStream: deserializeStream,
BSONError: error_1.BSONError,
BSONTypeError: error_1.BSONTypeError
};
exports.default = BSON;
//# sourceMappingURL=bson.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_LONG = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_INT = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_CODE = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_REGEXP = exports.BSON_DATA_NULL = exports.BSON_DATA_DATE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_OID = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_DATA_OBJECT = exports.BSON_DATA_STRING = exports.BSON_DATA_NUMBER = exports.JS_INT_MIN = exports.JS_INT_MAX = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = void 0;
exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_COLUMN = exports.BSON_BINARY_SUBTYPE_ENCRYPTED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_LONG = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_INT = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_CODE = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_REGEXP = exports.BSON_DATA_NULL = exports.BSON_DATA_DATE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_OID = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_DATA_OBJECT = exports.BSON_DATA_STRING = exports.BSON_DATA_NUMBER = exports.JS_INT_MIN = exports.JS_INT_MAX = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = void 0;
/** @internal */

@@ -76,4 +76,8 @@ exports.BSON_INT32_MAX = 0x7fffffff;

exports.BSON_BINARY_SUBTYPE_MD5 = 5;
/** Encrypted BSON type @internal */
exports.BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
/** Column BSON type @internal */
exports.BSON_BINARY_SUBTYPE_COLUMN = 7;
/** Binary User Defined Type @internal */
exports.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
//# sourceMappingURL=constants.js.map

@@ -5,2 +5,3 @@ "use strict";

var buffer_1 = require("buffer");
var error_1 = require("./error");
var long_1 = require("./long");

@@ -94,3 +95,3 @@ var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;

function invalidErr(string, message) {
throw new TypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
throw new error_1.BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
}

@@ -162,3 +163,3 @@ /**

if (representation.length >= 7000) {
throw new TypeError('' + representation + ' not a valid Decimal128 string');
throw new error_1.BSONTypeError('' + representation + ' not a valid Decimal128 string');
}

@@ -171,3 +172,3 @@ // Results

if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) {
throw new TypeError('' + representation + ' not a valid Decimal128 string');
throw new error_1.BSONTypeError('' + representation + ' not a valid Decimal128 string');
}

@@ -234,3 +235,3 @@ if (stringMatch) {

if (sawRadix && !nDigitsRead)
throw new TypeError('' + representation + ' not a valid Decimal128 string');
throw new error_1.BSONTypeError('' + representation + ' not a valid Decimal128 string');
// Read exponent if exists

@@ -237,0 +238,0 @@ if (representation[index] === 'e' || representation[index] === 'E') {

@@ -5,2 +5,3 @@ "use strict";

var buffer_1 = require("buffer");
var error_1 = require("./error");
var utils_1 = require("./parser/utils");

@@ -22,5 +23,5 @@ /**

}
throw new TypeError('Must use either Buffer or TypedArray');
throw new error_1.BSONTypeError('Must use either Buffer or TypedArray');
}
exports.ensureBuffer = ensureBuffer;
//# sourceMappingURL=ensure_buffer.js.map

@@ -9,2 +9,3 @@ "use strict";

var double_1 = require("./double");
var error_1 = require("./error");
var int_32_1 = require("./int_32");

@@ -156,3 +157,3 @@ var long_1 = require("./long");

var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
throw new TypeError('Converting circular structure to EJSON:\n' +
throw new error_1.BSONTypeError('Converting circular structure to EJSON:\n' +
(" " + leadingPart + alreadySeen + circularPart + current + "\n") +

@@ -230,3 +231,3 @@ (" " + leadingSpace + "\\" + dashes + "/"));

if (doc == null || typeof doc !== 'object')
throw new Error('not an object instance');
throw new error_1.BSONError('not an object instance');
var bsontype = doc._bsontype;

@@ -258,3 +259,3 @@ if (typeof bsontype === 'undefined') {

if (!mapper) {
throw new TypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
throw new error_1.BSONTypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
}

@@ -273,3 +274,3 @@ outDoc = mapper(outDoc);

else {
throw new Error('_bsontype must be a string, but was: ' + typeof bsontype);
throw new error_1.BSONError('_bsontype must be a string, but was: ' + typeof bsontype);
}

@@ -309,3 +310,8 @@ }

finalOptions.relaxed = !finalOptions.strict;
return JSON.parse(text, function (_key, value) { return deserializeValue(value, finalOptions); });
return JSON.parse(text, function (key, value) {
if (key.indexOf('\x00') !== -1) {
throw new error_1.BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
}
return deserializeValue(value, finalOptions);
});
}

@@ -312,0 +318,0 @@ EJSON.parse = parse;

@@ -6,2 +6,3 @@ "use strict";

var ensure_buffer_1 = require("./ensure_buffer");
var error_1 = require("./error");
var utils_1 = require("./parser/utils");

@@ -62,3 +63,3 @@ // Regular expression that checks for hex value

else {
throw new TypeError('Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters');
throw new error_1.BSONTypeError('Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters');
}

@@ -228,3 +229,3 @@ }

if (typeof hexString === 'undefined' || (hexString != null && hexString.length !== 24)) {
throw new TypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
throw new error_1.BSONTypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
}

@@ -231,0 +232,0 @@ return new ObjectId(buffer_1.Buffer.from(hexString, 'hex'));

@@ -11,2 +11,3 @@ "use strict";

var double_1 = require("../double");
var error_1 = require("../error");
var int_32_1 = require("../int_32");

@@ -34,16 +35,16 @@ var long_1 = require("../long");

if (size < 5) {
throw new Error("bson size must be >= 5, is " + size);
throw new error_1.BSONError("bson size must be >= 5, is " + size);
}
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
throw new Error("buffer length " + buffer.length + " must be >= bson size " + size);
throw new error_1.BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
}
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
throw new Error("buffer length " + buffer.length + " must === bson size " + size);
throw new error_1.BSONError("buffer length " + buffer.length + " must === bson size " + size);
}
if (size + index > buffer.byteLength) {
throw new Error("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
throw new error_1.BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
}
// Illegal end value
if (buffer[index + size - 1] !== 0) {
throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
throw new error_1.BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
}

@@ -72,3 +73,3 @@ // Start deserializtion

if (buffer.length < 5)
throw new Error('corrupt bson message < 5 bytes long');
throw new error_1.BSONError('corrupt bson message < 5 bytes long');
// Read the document size

@@ -78,3 +79,3 @@ var size = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);

if (size < 5 || size > buffer.length)
throw new Error('corrupt bson message');
throw new error_1.BSONError('corrupt bson message');
// Create holding object

@@ -101,3 +102,3 @@ var object = isArray ? [] : {};

if (i >= buffer.byteLength)
throw new Error('Bad BSON Document: illegal CString');
throw new error_1.BSONError('Bad BSON Document: illegal CString');
var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i);

@@ -116,13 +117,6 @@ if (isPossibleDBRef !== false && name[0] === '$') {

stringSize > buffer.length - index ||
buffer[index + stringSize - 1] !== 0)
throw new Error('bad string length in bson');
value = buffer.toString('utf8', index, index + stringSize - 1);
for (var i_1 = 0; i_1 < value.length; i_1++) {
if (value.charCodeAt(i_1) === 0xfffd) {
if (!validate_utf8_1.validateUtf8(buffer, index, index + stringSize - 1)) {
throw new Error('Invalid UTF-8 string in BSON document');
}
break;
}
buffer[index + stringSize - 1] !== 0) {
throw new error_1.BSONError('bad string length in bson');
}
value = getValidatedString(buffer, index, index + stringSize - 1);
index = index + stringSize;

@@ -167,3 +161,3 @@ }

if (buffer[index] !== 0 && buffer[index] !== 1)
throw new Error('illegal boolean type value');
throw new error_1.BSONError('illegal boolean type value');
value = buffer[index++] === 1;

@@ -178,3 +172,3 @@ }

if (objectSize <= 0 || objectSize > buffer.length - index)
throw new Error('bad embedded document length in bson');
throw new error_1.BSONError('bad embedded document length in bson');
// We have a raw value

@@ -209,5 +203,5 @@ if (raw) {

if (buffer[index - 1] !== 0)
throw new Error('invalid array terminator byte');
throw new error_1.BSONError('invalid array terminator byte');
if (index !== stopIndex)
throw new Error('corrupted array bson');
throw new error_1.BSONError('corrupted array bson');
}

@@ -268,6 +262,6 @@ else if (elementType === constants.BSON_DATA_UNDEFINED) {

if (binarySize < 0)
throw new Error('Negative binary type element size found');
throw new error_1.BSONError('Negative binary type element size found');
// Is the length longer than the document
if (binarySize > buffer.byteLength)
throw new Error('Binary type size larger than document size');
throw new error_1.BSONError('Binary type size larger than document size');
// Decode as raw Buffer object if options specifies it

@@ -283,7 +277,7 @@ if (buffer['slice'] != null) {

if (binarySize < 0)
throw new Error('Negative binary type element size found for subtype 0x02');
throw new error_1.BSONError('Negative binary type element size found for subtype 0x02');
if (binarySize > totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too long binary size');
throw new error_1.BSONError('Binary type with subtype 0x02 contains too long binary size');
if (binarySize < totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too short binary size');
throw new error_1.BSONError('Binary type with subtype 0x02 contains too short binary size');
}

@@ -307,7 +301,7 @@ if (promoteBuffers && promoteValues) {

if (binarySize < 0)
throw new Error('Negative binary type element size found for subtype 0x02');
throw new error_1.BSONError('Negative binary type element size found for subtype 0x02');
if (binarySize > totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too long binary size');
throw new error_1.BSONError('Binary type with subtype 0x02 contains too long binary size');
if (binarySize < totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too short binary size');
throw new error_1.BSONError('Binary type with subtype 0x02 contains too short binary size');
}

@@ -337,3 +331,3 @@ // Copy the data

if (i >= buffer.length)
throw new Error('Bad BSON Document: illegal CString');
throw new error_1.BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -351,3 +345,3 @@ var source = buffer.toString('utf8', index, i);

if (i >= buffer.length)
throw new Error('Bad BSON Document: illegal CString');
throw new error_1.BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -383,3 +377,3 @@ var regExpOptions = buffer.toString('utf8', index, i);

if (i >= buffer.length)
throw new Error('Bad BSON Document: illegal CString');
throw new error_1.BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -396,3 +390,3 @@ var source = buffer.toString('utf8', index, i);

if (i >= buffer.length)
throw new Error('Bad BSON Document: illegal CString');
throw new error_1.BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -411,5 +405,6 @@ var regExpOptions = buffer.toString('utf8', index, i);

stringSize > buffer.length - index ||
buffer[index + stringSize - 1] !== 0)
throw new Error('bad string length in bson');
var symbol = buffer.toString('utf8', index, index + stringSize - 1);
buffer[index + stringSize - 1] !== 0) {
throw new error_1.BSONError('bad string length in bson');
}
var symbol = getValidatedString(buffer, index, index + stringSize - 1);
value = promoteValues ? symbol : new symbol_1.BSONSymbol(symbol);

@@ -442,5 +437,6 @@ index = index + stringSize;

stringSize > buffer.length - index ||
buffer[index + stringSize - 1] !== 0)
throw new Error('bad string length in bson');
var functionString = buffer.toString('utf8', index, index + stringSize - 1);
buffer[index + stringSize - 1] !== 0) {
throw new error_1.BSONError('bad string length in bson');
}
var functionString = getValidatedString(buffer, index, index + stringSize - 1);
// If we are evaluating the functions

@@ -470,3 +466,3 @@ if (evalFunctions) {

if (totalSize < 4 + 4 + 4 + 1) {
throw new Error('code_w_scope total size shorter minimum expected length');
throw new error_1.BSONError('code_w_scope total size shorter minimum expected length');
}

@@ -481,6 +477,7 @@ // Get the code string size

stringSize > buffer.length - index ||
buffer[index + stringSize - 1] !== 0)
throw new Error('bad string length in bson');
buffer[index + stringSize - 1] !== 0) {
throw new error_1.BSONError('bad string length in bson');
}
// Javascript function
var functionString = buffer.toString('utf8', index, index + stringSize - 1);
var functionString = getValidatedString(buffer, index, index + stringSize - 1);
// Update parse index position

@@ -501,7 +498,7 @@ index = index + stringSize;

if (totalSize < 4 + 4 + objectSize + stringSize) {
throw new Error('code_w_scope total size is too short, truncating scope');
throw new error_1.BSONError('code_w_scope total size is too short, truncating scope');
}
// Check if totalSize field is too long
if (totalSize > 4 + 4 + objectSize + stringSize) {
throw new Error('code_w_scope total size is too long, clips outer document');
throw new error_1.BSONError('code_w_scope total size is too long, clips outer document');
}

@@ -534,6 +531,6 @@ // If we are evaluating the functions

buffer[index + stringSize - 1] !== 0)
throw new Error('bad string length in bson');
throw new error_1.BSONError('bad string length in bson');
// Namespace
if (!validate_utf8_1.validateUtf8(buffer, index, index + stringSize - 1)) {
throw new Error('Invalid UTF-8 string in BSON document');
throw new error_1.BSONError('Invalid UTF-8 string in BSON document');
}

@@ -553,3 +550,3 @@ var namespace = buffer.toString('utf8', index, index + stringSize - 1);

else {
throw new Error('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
throw new error_1.BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
}

@@ -571,4 +568,4 @@ if (name === '__proto__') {

if (isArray)
throw new Error('corrupt array bson');
throw new Error('corrupt object bson');
throw new error_1.BSONError('corrupt array bson');
throw new error_1.BSONError('corrupt object bson');
}

@@ -602,2 +599,14 @@ // if we did not find "$ref", "$id", "$db", or found an extraneous $key, don't make a DBRef

}
function getValidatedString(buffer, start, end) {
var value = buffer.toString('utf8', start, end);
for (var i = 0; i < value.length; i++) {
if (value.charCodeAt(i) === 0xfffd) {
if (!validate_utf8_1.validateUtf8(buffer, start, end)) {
throw new error_1.BSONError('Invalid UTF-8 string in BSON document');
}
break;
}
}
return value;
}
//# sourceMappingURL=deserializer.js.map

@@ -7,2 +7,3 @@ "use strict";

var ensure_buffer_1 = require("../ensure_buffer");
var error_1 = require("../error");
var extended_json_1 = require("../extended_json");

@@ -228,3 +229,3 @@ var float_parser_1 = require("../float_parser");

else {
throw new TypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
throw new error_1.BSONTypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
}

@@ -268,3 +269,3 @@ // Adjust index

if (path[i] === value)
throw new Error('cyclic dependency detected');
throw new error_1.BSONError('cyclic dependency detected');
}

@@ -574,3 +575,3 @@ // Push value to stack

if (typeof value.toBSON !== 'function')
throw new TypeError('toBSON is not a function');
throw new error_1.BSONTypeError('toBSON is not a function');
value = value.toBSON();

@@ -585,3 +586,3 @@ }

else if (typeof value === 'bigint') {
throw new TypeError('Unsupported type BigInt, please use Decimal128');
throw new error_1.BSONTypeError('Unsupported type BigInt, please use Decimal128');
}

@@ -648,3 +649,3 @@ else if (typeof value === 'boolean') {

else if (typeof value['_bsontype'] !== 'undefined') {
throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
throw new error_1.BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
}

@@ -691,3 +692,3 @@ }

else if (type === 'bigint' || utils_1.isBigInt64Array(value) || utils_1.isBigUInt64Array(value)) {
throw new TypeError('Unsupported type BigInt, please use Decimal128');
throw new error_1.BSONTypeError('Unsupported type BigInt, please use Decimal128');
}

@@ -749,3 +750,3 @@ else if (type === 'boolean') {

else if (typeof value['_bsontype'] !== 'undefined') {
throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
throw new error_1.BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
}

@@ -758,6 +759,6 @@ }

if (typeof object.toBSON !== 'function')
throw new TypeError('toBSON is not a function');
throw new error_1.BSONTypeError('toBSON is not a function');
object = object.toBSON();
if (object != null && typeof object !== 'object')
throw new TypeError('toBSON function did not return an object');
throw new error_1.BSONTypeError('toBSON function did not return an object');
}

@@ -770,3 +771,3 @@ // Iterate over all the keys

if (typeof value.toBSON !== 'function')
throw new TypeError('toBSON is not a function');
throw new error_1.BSONTypeError('toBSON is not a function');
value = value.toBSON();

@@ -799,3 +800,3 @@ }

else if (type === 'bigint') {
throw new TypeError('Unsupported type BigInt, please use Decimal128');
throw new error_1.BSONTypeError('Unsupported type BigInt, please use Decimal128');
}

@@ -861,3 +862,3 @@ else if (type === 'boolean') {

else if (typeof value['_bsontype'] !== 'undefined') {
throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
throw new error_1.BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
}

@@ -864,0 +865,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BSONRegExp = void 0;
var error_1 = require("./error");
function alphabetize(str) {

@@ -21,2 +22,8 @@ return str.split('').sort().join('');

this.options = alphabetize(options !== null && options !== void 0 ? options : '');
if (this.pattern.indexOf('\x00') !== -1) {
throw new error_1.BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
}
if (this.options.indexOf('\x00') !== -1) {
throw new error_1.BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
}
// Validate options

@@ -30,3 +37,3 @@ for (var i = 0; i < this.options.length; i++) {

this.options[i] === 'u')) {
throw new Error("The regular expression option [" + this.options[i] + "] is not supported");
throw new error_1.BSONError("The regular expression option [" + this.options[i] + "] is not supported");
}

@@ -62,3 +69,3 @@ }

}
throw new TypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
throw new error_1.BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
};

@@ -65,0 +72,0 @@ return BSONRegExp;

@@ -5,2 +5,3 @@ "use strict";

var buffer_1 = require("buffer");
var error_1 = require("./error");
// Validation regex for v4 uuid (validates with or without dashes)

@@ -14,3 +15,3 @@ var VALIDATION_REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i;

if (!exports.uuidValidateString(hexString)) {
throw new TypeError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');
throw new error_1.BSONTypeError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');
}

@@ -17,0 +18,0 @@ var sanitizedHexString = hexString.replace(/-/g, '');

@@ -9,2 +9,3 @@ "use strict";

var utils_1 = require("./parser/utils");
var error_1 = require("./error");
var BYTE_LENGTH = 16;

@@ -38,3 +39,3 @@ var kId = Symbol('id');

else {
throw new TypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
throw new error_1.BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
}

@@ -41,0 +42,0 @@ }

@@ -18,3 +18,3 @@ {

"types": "bson.d.ts",
"version": "4.5.2",
"version": "4.5.3",
"author": {

@@ -42,2 +42,3 @@ "name": "The MongoDB NodeJS Team",

"@typescript-eslint/parser": "^3.10.1",
"array-includes": "^3.1.3",
"benchmark": "^2.1.4",

@@ -59,2 +60,3 @@ "chai": "^4.2.0",

"nyc": "^15.1.0",
"object.entries": "^1.1.4",
"prettier": "^2.1.1",

@@ -61,0 +63,0 @@ "rimraf": "^3.0.2",

@@ -6,2 +6,3 @@ import { Buffer } from 'buffer';

import type { EJSONOptions } from './extended_json';
import { BSONError, BSONTypeError } from './error';

@@ -52,2 +53,6 @@ /** @public */

static readonly SUBTYPE_MD5 = 5;
/** Encrypted BSON type */
static readonly SUBTYPE_ENCRYPTED = 6;
/** Column BSON type */
static readonly SUBTYPE_COLUMN = 7;
/** User BSON type */

@@ -74,3 +79,3 @@ static readonly SUBTYPE_USER_DEFINED = 128;

) {
throw new TypeError(
throw new BSONTypeError(
'Binary can only be constructed from string, Buffer, TypedArray, or Array<number>'

@@ -110,5 +115,5 @@ );

if (typeof byteValue === 'string' && byteValue.length !== 1) {
throw new TypeError('only accepts single character String');
throw new BSONTypeError('only accepts single character String');
} else if (typeof byteValue !== 'number' && byteValue.length !== 1)
throw new TypeError('only accepts single character Uint8Array or Array');
throw new BSONTypeError('only accepts single character Uint8Array or Array');

@@ -126,3 +131,3 @@ // Decode the byte value once

if (decodedByte < 0 || decodedByte > 255) {
throw new TypeError('only accepts number in a valid unsigned byte range 0-255');
throw new BSONTypeError('only accepts number in a valid unsigned byte range 0-255');
}

@@ -242,3 +247,3 @@

throw new Error(
throw new BSONError(
`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`

@@ -271,3 +276,3 @@ );

if (!data) {
throw new TypeError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
throw new BSONTypeError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
}

@@ -274,0 +279,0 @@ return new Binary(data, type);

@@ -15,2 +15,3 @@ import { Buffer } from 'buffer';

import { ObjectId } from './objectid';
import { BSONError, BSONTypeError } from './error';
import { calculateObjectSize as internalCalculateObjectSize } from './parser/calculate_size';

@@ -34,2 +35,4 @@ // Parts of the parser

BSON_BINARY_SUBTYPE_UUID_NEW,
BSON_BINARY_SUBTYPE_ENCRYPTED,
BSON_BINARY_SUBTYPE_COLUMN,
BSON_DATA_ARRAY,

@@ -101,2 +104,3 @@ BSON_DATA_BINARY,

};
export { BSONError, BSONTypeError } from './error';

@@ -330,4 +334,6 @@ /** @public */

calculateObjectSize,
deserializeStream
deserializeStream,
BSONError,
BSONTypeError
};
export default BSON;

@@ -103,3 +103,9 @@ /** @internal */

/** Encrypted BSON type @internal */
export const BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
/** Column BSON type @internal */
export const BSON_BINARY_SUBTYPE_COLUMN = 7;
/** Binary User Defined Type @internal */
export const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
import { Buffer } from 'buffer';
import { BSONTypeError } from './error';
import { Long } from './long';

@@ -108,3 +109,3 @@

function invalidErr(string: string, message: string) {
throw new TypeError(`"${string}" is not a valid Decimal128 string - ${message}`);
throw new BSONTypeError(`"${string}" is not a valid Decimal128 string - ${message}`);
}

@@ -191,3 +192,3 @@

if (representation.length >= 7000) {
throw new TypeError('' + representation + ' not a valid Decimal128 string');
throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
}

@@ -202,3 +203,3 @@

if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) {
throw new TypeError('' + representation + ' not a valid Decimal128 string');
throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
}

@@ -275,3 +276,3 @@

if (sawRadix && !nDigitsRead)
throw new TypeError('' + representation + ' not a valid Decimal128 string');
throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');

@@ -278,0 +279,0 @@ // Read exponent if exists

import { Buffer } from 'buffer';
import { BSONTypeError } from './error';
import { isAnyArrayBuffer } from './parser/utils';

@@ -25,3 +26,3 @@

throw new TypeError('Must use either Buffer or TypedArray');
throw new BSONTypeError('Must use either Buffer or TypedArray');
}

@@ -7,2 +7,3 @@ import { Binary } from './binary';

import { Double } from './double';
import { BSONError, BSONTypeError } from './error';
import { Int32 } from './int_32';

@@ -189,3 +190,3 @@ import { Long } from './long';

throw new TypeError(
throw new BSONTypeError(
'Converting circular structure to EJSON:\n' +

@@ -279,3 +280,3 @@ ` ${leadingPart}${alreadySeen}${circularPart}${current}\n` +

function serializeDocument(doc: any, options: EJSONSerializeOptions) {
if (doc == null || typeof doc !== 'object') throw new Error('not an object instance');
if (doc == null || typeof doc !== 'object') throw new BSONError('not an object instance');

@@ -306,3 +307,3 @@ const bsontype: BSONType['_bsontype'] = doc._bsontype;

if (!mapper) {
throw new TypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
}

@@ -326,3 +327,3 @@ outDoc = mapper(outDoc);

} else {
throw new Error('_bsontype must be a string, but was: ' + typeof bsontype);
throw new BSONError('_bsontype must be a string, but was: ' + typeof bsontype);
}

@@ -374,3 +375,10 @@ }

return JSON.parse(text, (_key, value) => deserializeValue(value, finalOptions));
return JSON.parse(text, (key, value) => {
if (key.indexOf('\x00') !== -1) {
throw new BSONError(
`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`
);
}
return deserializeValue(value, finalOptions);
});
}

@@ -377,0 +385,0 @@

import { Buffer } from 'buffer';
import { ensureBuffer } from './ensure_buffer';
import { BSONTypeError } from './error';
import { deprecate, isUint8Array, randomBytes } from './parser/utils';

@@ -87,3 +88,3 @@

} else {
throw new TypeError(
throw new BSONTypeError(
'Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters'

@@ -280,3 +281,3 @@ );

if (typeof hexString === 'undefined' || (hexString != null && hexString.length !== 24)) {
throw new TypeError(
throw new BSONTypeError(
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'

@@ -283,0 +284,0 @@ );

@@ -9,2 +9,3 @@ import { Buffer } from 'buffer';

import { Double } from '../double';
import { BSONError } from '../error';
import { Int32 } from '../int_32';

@@ -71,15 +72,15 @@ import { Long } from '../long';

if (size < 5) {
throw new Error(`bson size must be >= 5, is ${size}`);
throw new BSONError(`bson size must be >= 5, is ${size}`);
}
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
throw new Error(`buffer length ${buffer.length} must be >= bson size ${size}`);
throw new BSONError(`buffer length ${buffer.length} must be >= bson size ${size}`);
}
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
throw new Error(`buffer length ${buffer.length} must === bson size ${size}`);
throw new BSONError(`buffer length ${buffer.length} must === bson size ${size}`);
}
if (size + index > buffer.byteLength) {
throw new Error(
throw new BSONError(
`(bson size ${size} + options.index ${index} must be <= buffer length ${buffer.byteLength})`

@@ -91,3 +92,5 @@ );

if (buffer[index + size - 1] !== 0) {
throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
throw new BSONError(
"One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00"
);
}

@@ -127,3 +130,3 @@

// Validate that we have at least 4 bytes of buffer
if (buffer.length < 5) throw new Error('corrupt bson message < 5 bytes long');
if (buffer.length < 5) throw new BSONError('corrupt bson message < 5 bytes long');

@@ -135,3 +138,3 @@ // Read the document size

// Ensure buffer is valid size
if (size < 5 || size > buffer.length) throw new Error('corrupt bson message');
if (size < 5 || size > buffer.length) throw new BSONError('corrupt bson message');

@@ -162,3 +165,3 @@ // Create holding object

// If are at the end of the buffer there is a problem with the document
if (i >= buffer.byteLength) throw new Error('Bad BSON Document: illegal CString');
if (i >= buffer.byteLength) throw new BSONError('Bad BSON Document: illegal CString');
const name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i);

@@ -182,16 +185,8 @@ if (isPossibleDBRef !== false && (name as string)[0] === '$') {

buffer[index + stringSize - 1] !== 0
)
throw new Error('bad string length in bson');
) {
throw new BSONError('bad string length in bson');
}
value = buffer.toString('utf8', index, index + stringSize - 1);
value = getValidatedString(buffer, index, index + stringSize - 1);
for (let i = 0; i < value.length; i++) {
if (value.charCodeAt(i) === 0xfffd) {
if (!validateUtf8(buffer, index, index + stringSize - 1)) {
throw new Error('Invalid UTF-8 string in BSON document');
}
break;
}
}
index = index + stringSize;

@@ -232,3 +227,4 @@ } else if (elementType === constants.BSON_DATA_OID) {

} else if (elementType === constants.BSON_DATA_BOOLEAN) {
if (buffer[index] !== 0 && buffer[index] !== 1) throw new Error('illegal boolean type value');
if (buffer[index] !== 0 && buffer[index] !== 1)
throw new BSONError('illegal boolean type value');
value = buffer[index++] === 1;

@@ -243,3 +239,3 @@ } else if (elementType === constants.BSON_DATA_OBJECT) {

if (objectSize <= 0 || objectSize > buffer.length - index)
throw new Error('bad embedded document length in bson');
throw new BSONError('bad embedded document length in bson');

@@ -282,4 +278,4 @@ // We have a raw value

if (buffer[index - 1] !== 0) throw new Error('invalid array terminator byte');
if (index !== stopIndex) throw new Error('corrupted array bson');
if (buffer[index - 1] !== 0) throw new BSONError('invalid array terminator byte');
if (index !== stopIndex) throw new BSONError('corrupted array bson');
} else if (elementType === constants.BSON_DATA_UNDEFINED) {

@@ -336,7 +332,7 @@ value = undefined;

// Did we have a negative binary size, throw
if (binarySize < 0) throw new Error('Negative binary type element size found');
if (binarySize < 0) throw new BSONError('Negative binary type element size found');
// Is the length longer than the document
if (binarySize > buffer.byteLength)
throw new Error('Binary type size larger than document size');
throw new BSONError('Binary type size larger than document size');

@@ -353,7 +349,7 @@ // Decode as raw Buffer object if options specifies it

if (binarySize < 0)
throw new Error('Negative binary type element size found for subtype 0x02');
throw new BSONError('Negative binary type element size found for subtype 0x02');
if (binarySize > totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too long binary size');
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
if (binarySize < totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too short binary size');
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
}

@@ -376,7 +372,7 @@

if (binarySize < 0)
throw new Error('Negative binary type element size found for subtype 0x02');
throw new BSONError('Negative binary type element size found for subtype 0x02');
if (binarySize > totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too long binary size');
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
if (binarySize < totalBinarySize - 4)
throw new Error('Binary type with subtype 0x02 contains too short binary size');
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
}

@@ -406,3 +402,3 @@

// If are at the end of the buffer there is a problem with the document
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString');
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -420,3 +416,3 @@ const source = buffer.toString('utf8', index, i);

// If are at the end of the buffer there is a problem with the document
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString');
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -453,3 +449,3 @@ const regExpOptions = buffer.toString('utf8', index, i);

// If are at the end of the buffer there is a problem with the document
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString');
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -466,3 +462,3 @@ const source = buffer.toString('utf8', index, i);

// If are at the end of the buffer there is a problem with the document
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString');
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
// Return the C string

@@ -484,5 +480,6 @@ const regExpOptions = buffer.toString('utf8', index, i);

buffer[index + stringSize - 1] !== 0
)
throw new Error('bad string length in bson');
const symbol = buffer.toString('utf8', index, index + stringSize - 1);
) {
throw new BSONError('bad string length in bson');
}
const symbol = getValidatedString(buffer, index, index + stringSize - 1);
value = promoteValues ? symbol : new BSONSymbol(symbol);

@@ -517,5 +514,6 @@ index = index + stringSize;

buffer[index + stringSize - 1] !== 0
)
throw new Error('bad string length in bson');
const functionString = buffer.toString('utf8', index, index + stringSize - 1);
) {
throw new BSONError('bad string length in bson');
}
const functionString = getValidatedString(buffer, index, index + stringSize - 1);

@@ -546,3 +544,3 @@ // If we are evaluating the functions

if (totalSize < 4 + 4 + 4 + 1) {
throw new Error('code_w_scope total size shorter minimum expected length');
throw new BSONError('code_w_scope total size shorter minimum expected length');
}

@@ -561,7 +559,8 @@

buffer[index + stringSize - 1] !== 0
)
throw new Error('bad string length in bson');
) {
throw new BSONError('bad string length in bson');
}
// Javascript function
const functionString = buffer.toString('utf8', index, index + stringSize - 1);
const functionString = getValidatedString(buffer, index, index + stringSize - 1);
// Update parse index position

@@ -584,3 +583,3 @@ index = index + stringSize;

if (totalSize < 4 + 4 + objectSize + stringSize) {
throw new Error('code_w_scope total size is too short, truncating scope');
throw new BSONError('code_w_scope total size is too short, truncating scope');
}

@@ -590,3 +589,3 @@

if (totalSize > 4 + 4 + objectSize + stringSize) {
throw new Error('code_w_scope total size is too long, clips outer document');
throw new BSONError('code_w_scope total size is too long, clips outer document');
}

@@ -621,6 +620,6 @@

)
throw new Error('bad string length in bson');
throw new BSONError('bad string length in bson');
// Namespace
if (!validateUtf8(buffer, index, index + stringSize - 1)) {
throw new Error('Invalid UTF-8 string in BSON document');
throw new BSONError('Invalid UTF-8 string in BSON document');
}

@@ -642,3 +641,3 @@ const namespace = buffer.toString('utf8', index, index + stringSize - 1);

} else {
throw new Error(
throw new BSONError(
'Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"'

@@ -661,4 +660,4 @@ );

if (size !== index - startIndex) {
if (isArray) throw new Error('corrupt array bson');
throw new Error('corrupt object bson');
if (isArray) throw new BSONError('corrupt array bson');
throw new BSONError('corrupt object bson');
}

@@ -699,1 +698,14 @@

}
function getValidatedString(buffer: Buffer, start: number, end: number) {
const value = buffer.toString('utf8', start, end);
for (let i = 0; i < value.length; i++) {
if (value.charCodeAt(i) === 0xfffd) {
if (!validateUtf8(buffer, start, end)) {
throw new BSONError('Invalid UTF-8 string in BSON document');
}
break;
}
}
return value;
}

@@ -10,2 +10,3 @@ import type { Buffer } from 'buffer';

import { ensureBuffer } from '../ensure_buffer';
import { BSONError, BSONTypeError } from '../error';
import { isBSONType } from '../extended_json';

@@ -315,3 +316,3 @@ import { writeIEEE754 } from '../float_parser';

} else {
throw new TypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
throw new BSONTypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
}

@@ -368,3 +369,3 @@

for (let i = 0; i < path.length; i++) {
if (path[i] === value) throw new Error('cyclic dependency detected');
if (path[i] === value) throw new BSONError('cyclic dependency detected');
}

@@ -773,3 +774,3 @@

if (value && value.toBSON) {
if (typeof value.toBSON !== 'function') throw new TypeError('toBSON is not a function');
if (typeof value.toBSON !== 'function') throw new BSONTypeError('toBSON is not a function');
value = value.toBSON();

@@ -783,3 +784,3 @@ }

} else if (typeof value === 'bigint') {
throw new TypeError('Unsupported type BigInt, please use Decimal128');
throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
} else if (typeof value === 'boolean') {

@@ -849,3 +850,3 @@ index = serializeBoolean(buffer, key, value, index, true);

} else if (typeof value['_bsontype'] !== 'undefined') {
throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
}

@@ -893,3 +894,3 @@ }

} else if (type === 'bigint' || isBigInt64Array(value) || isBigUInt64Array(value)) {
throw new TypeError('Unsupported type BigInt, please use Decimal128');
throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
} else if (type === 'boolean') {

@@ -952,3 +953,3 @@ index = serializeBoolean(buffer, key, value, index);

} else if (typeof value['_bsontype'] !== 'undefined') {
throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
}

@@ -959,6 +960,6 @@ }

if (object.toBSON) {
if (typeof object.toBSON !== 'function') throw new TypeError('toBSON is not a function');
if (typeof object.toBSON !== 'function') throw new BSONTypeError('toBSON is not a function');
object = object.toBSON();
if (object != null && typeof object !== 'object')
throw new TypeError('toBSON function did not return an object');
throw new BSONTypeError('toBSON function did not return an object');
}

@@ -971,3 +972,3 @@

if (value && value.toBSON) {
if (typeof value.toBSON !== 'function') throw new TypeError('toBSON is not a function');
if (typeof value.toBSON !== 'function') throw new BSONTypeError('toBSON is not a function');
value = value.toBSON();

@@ -1001,3 +1002,3 @@ }

} else if (type === 'bigint') {
throw new TypeError('Unsupported type BigInt, please use Decimal128');
throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
} else if (type === 'boolean') {

@@ -1062,3 +1063,3 @@ index = serializeBoolean(buffer, key, value, index);

} else if (typeof value['_bsontype'] !== 'undefined') {
throw new TypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
}

@@ -1065,0 +1066,0 @@ }

@@ -0,1 +1,2 @@

import { BSONError, BSONTypeError } from './error';
import type { EJSONOptions } from './extended_json';

@@ -40,2 +41,13 @@

if (this.pattern.indexOf('\x00') !== -1) {
throw new BSONError(
`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`
);
}
if (this.options.indexOf('\x00') !== -1) {
throw new BSONError(
`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`
);
}
// Validate options

@@ -53,3 +65,3 @@ for (let i = 0; i < this.options.length; i++) {

) {
throw new Error(`The regular expression option [${this.options[i]}] is not supported`);
throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
}

@@ -90,3 +102,3 @@ }

}
throw new TypeError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
throw new BSONTypeError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
}

@@ -93,0 +105,0 @@ }

import { Buffer } from 'buffer';
import { BSONTypeError } from './error';

@@ -12,3 +13,3 @@ // Validation regex for v4 uuid (validates with or without dashes)

if (!uuidValidateString(hexString)) {
throw new TypeError(
throw new BSONTypeError(
'UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".'

@@ -15,0 +16,0 @@ );

@@ -6,2 +6,3 @@ import { Buffer } from 'buffer';

import { isUint8Array, randomBytes } from './parser/utils';
import { BSONTypeError } from './error';

@@ -49,3 +50,3 @@ /** @public */

} else {
throw new TypeError(
throw new BSONTypeError(
'Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).'

@@ -52,0 +53,0 @@ );

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc