You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
Maintainers
8
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.2.0 to 6.3.0

src/utils/latin.ts

43

bson.d.ts

@@ -153,3 +153,3 @@ /**

*
* `BSONError` objects are thrown when BSON ecounters an error.
* `BSONError` objects are thrown when BSON encounters an error.
*

@@ -161,3 +161,5 @@ * This is the parent class for all the other errors thrown by this library.

get name(): string;
constructor(message: string);
constructor(message: string, options?: {
cause?: unknown;
});
/**

@@ -999,6 +1001,39 @@ * @public

/**
* Create an ObjectId type
* Create ObjectId from a number.
*
* @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
* @param inputId - A number.
* @deprecated Instead, use `static createFromTime()` to set a numeric value for the new ObjectId.
*/
constructor(inputId: number);
/**
* Create ObjectId from a 24 character hex string.
*
* @param inputId - A 24 character hex string.
*/
constructor(inputId: string);
/**
* Create ObjectId from the BSON ObjectId type.
*
* @param inputId - The BSON ObjectId type.
*/
constructor(inputId: ObjectId);
/**
* Create ObjectId from the object type that has the toHexString method.
*
* @param inputId - The ObjectIdLike type.
*/
constructor(inputId: ObjectIdLike);
/**
* Create ObjectId from a 12 byte binary Buffer.
*
* @param inputId - A 12 byte binary Buffer.
*/
constructor(inputId: Uint8Array);
/** To generate a new ObjectId, use ObjectId() with no argument. */
constructor();
/**
* Implementation overload.
*
* @param inputId - All input types that are used in the constructor implementation.
*/
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);

@@ -1005,0 +1040,0 @@ /**

35

package.json

@@ -17,3 +17,3 @@ {

"types": "bson.d.ts",
"version": "6.2.0",
"version": "6.3.0",
"author": {

@@ -31,17 +31,18 @@ "name": "The MongoDB NodeJS Team",

"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@microsoft/api-extractor": "^7.36.4",
"@microsoft/api-extractor": "^7.38.4",
"@octokit/core": "^4.2.4",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^18.17.3",
"@types/sinon": "^10.0.16",
"@types/sinon-chai": "^3.2.9",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
"@types/node": "^18.19.2",
"@types/sinon": "^10.0.20",
"@types/sinon-chai": "^3.2.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"benchmark": "^2.1.4",
"chai": "^4.3.7",
"chai": "^4.3.10",
"chalk": "^5.3.0",
"eslint": "^8.46.0",
"dbx-js-tools": "github:mongodb-js/dbx-js-tools",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.10.0",

@@ -51,3 +52,3 @@ "eslint-plugin-no-bigint-usage": "file:etc/eslint/no-bigint-usage",

"eslint-plugin-tsdoc": "^0.2.17",
"magic-string": "^0.30.2",
"magic-string": "^0.30.5",
"mocha": "10.2.0",

@@ -57,3 +58,3 @@ "node-fetch": "^3.3.2",

"prettier": "^2.8.8",
"rollup": "^3.27.2",
"rollup": "^3.29.4",
"sinon": "^15.2.0",

@@ -63,3 +64,3 @@ "sinon-chai": "^3.7.0",

"standard-version": "^9.5.0",
"tar": "^6.1.15",
"tar": "^6.2.0",
"ts-node": "^10.9.1",

@@ -69,3 +70,3 @@ "tsd": "^0.28.1",

"typescript-cached-transpile": "0.0.6",
"uuid": "^9.0.0"
"uuid": "^9.0.1"
},

@@ -112,3 +113,5 @@ "tsd": {

"check:web-no-bigint": "WEB=true NO_BIGINT=true mocha test/node",
"check:bench": "cd test/bench && npx tsc && node ./lib/index.js && mv benchmarks.json ../../.",
"check:granular-bench": "npm run build:bench && node ./test/bench/etc/run_granular_benchmarks.js",
"check:spec-bench": "npm run build:bench && node ./test/bench/lib/spec/bsonBench.js",
"build:bench": "cd test/bench && npx tsc",
"build:ts": "node ./node_modules/typescript/bin/tsc",

@@ -115,0 +118,0 @@ "build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && node etc/clean_definition_files.cjs",

@@ -194,4 +194,4 @@ import { type InspectFn, defaultInspect, isAnyArrayBuffer, isUint8Array } from './parser/utils';

if (encoding === 'utf8' || encoding === 'utf-8')
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength, false);
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength, false);
}

@@ -198,0 +198,0 @@

@@ -7,3 +7,3 @@ import { BSON_MAJOR_VERSION } from './constants';

*
* `BSONError` objects are thrown when BSON ecounters an error.
* `BSONError` objects are thrown when BSON encounters an error.
*

@@ -27,4 +27,4 @@ * This is the parent class for all the other errors thrown by this library.

constructor(message: string) {
super(message);
constructor(message: string, options?: { cause?: unknown }) {
super(message, options);
}

@@ -31,0 +31,0 @@

@@ -47,6 +47,45 @@ import { BSONValue } from './bson_value';

/**
* Create an ObjectId type
* Create ObjectId from a number.
*
* @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
* @param inputId - A number.
* @deprecated Instead, use `static createFromTime()` to set a numeric value for the new ObjectId.
*/
constructor(inputId: number);
/**
* Create ObjectId from a 24 character hex string.
*
* @param inputId - A 24 character hex string.
*/
constructor(inputId: string);
/**
* Create ObjectId from the BSON ObjectId type.
*
* @param inputId - The BSON ObjectId type.
*/
constructor(inputId: ObjectId);
/**
* Create ObjectId from the object type that has the toHexString method.
*
* @param inputId - The ObjectIdLike type.
*/
constructor(inputId: ObjectIdLike);
/**
* Create ObjectId from a 12 byte binary Buffer.
*
* @param inputId - A 12 byte binary Buffer.
*/
constructor(inputId: Uint8Array);
/** To generate a new ObjectId, use ObjectId() with no argument. */
constructor();
/**
* Implementation overload.
*
* @param inputId - All input types that are used in the constructor implementation.
*/
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
/**
* Create a new ObjectId.
*
* @param inputId - An input value to create a new ObjectId from.
*/
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array) {

@@ -69,3 +108,3 @@ super();

// the following cases use workingId to construct an ObjectId
// The following cases use workingId to construct an ObjectId
if (workingId == null || typeof workingId === 'number') {

@@ -72,0 +111,0 @@ // The most common use case (blank id, new objectId instance)

@@ -239,3 +239,3 @@ import { Binary, UUID } from '../binary';

// Represents the key
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i);
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i, false);

@@ -270,3 +270,3 @@ // shouldValidateKey is true if the key should be validated, false otherwise

}
value = getValidatedString(buffer, index, index + stringSize - 1, shouldValidateKey);
value = ByteUtils.toUTF8(buffer, index, index + stringSize - 1, shouldValidateKey);
index = index + stringSize;

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

// Return the C string
const source = ByteUtils.toUTF8(buffer, index, i);
const source = ByteUtils.toUTF8(buffer, index, i, false);
// Create the regexp

@@ -495,3 +495,3 @@ index = i + 1;

// Return the C string
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
const regExpOptions = ByteUtils.toUTF8(buffer, index, i, false);
index = i + 1;

@@ -528,3 +528,3 @@

// Return the C string
const source = ByteUtils.toUTF8(buffer, index, i);
const source = ByteUtils.toUTF8(buffer, index, i, false);
index = i + 1;

@@ -541,3 +541,3 @@

// Return the C string
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
const regExpOptions = ByteUtils.toUTF8(buffer, index, i, false);
index = i + 1;

@@ -560,3 +560,3 @@

}
const symbol = getValidatedString(buffer, index, index + stringSize - 1, shouldValidateKey);
const symbol = ByteUtils.toUTF8(buffer, index, index + stringSize - 1, shouldValidateKey);
value = promoteValues ? symbol : new BSONSymbol(symbol);

@@ -597,3 +597,3 @@ index = index + stringSize;

}
const functionString = getValidatedString(
const functionString = ByteUtils.toUTF8(
buffer,

@@ -637,3 +637,3 @@ index,

// Javascript function
const functionString = getValidatedString(
const functionString = ByteUtils.toUTF8(
buffer,

@@ -690,3 +690,3 @@ index,

}
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1);
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1, false);
// Update parse index position

@@ -741,22 +741,1 @@ index = index + stringSize;

}
function getValidatedString(
buffer: Uint8Array,
start: number,
end: number,
shouldValidateUtf8: boolean
) {
const value = ByteUtils.toUTF8(buffer, start, end);
// if utf8 validation is on, do the check
if (shouldValidateUtf8) {
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;
}

@@ -28,4 +28,4 @@ import { nodeJsByteUtils } from './node_byte_utils';

fromUTF8: (text: string) => Uint8Array;
/** Create a string from utf8 code units */
toUTF8: (buffer: Uint8Array, start: number, end: number) => string;
/** Create a string from utf8 code units, fatal=true will throw an error if UTF-8 bytes are invalid, fatal=false will insert replacement characters */
toUTF8: (buffer: Uint8Array, start: number, end: number, fatal: boolean) => string;
/** Get the utf8 code unit count from a string if it were to be transformed to utf8 */

@@ -32,0 +32,0 @@ utf8ByteLength: (input: string) => number;

import { BSONError } from '../error';
import { validateUtf8 } from '../validate_utf8';
import { tryLatin } from './latin';

@@ -128,4 +130,21 @@ type NodeJsEncoding = 'base64' | 'hex' | 'utf8' | 'binary';

toUTF8(buffer: Uint8Array, start: number, end: number): string {
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
toUTF8(buffer: Uint8Array, start: number, end: number, fatal: boolean): string {
const basicLatin = end - start <= 20 ? tryLatin(buffer, start, end) : null;
if (basicLatin != null) {
return basicLatin;
}
const string = nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
if (fatal) {
// TODO(NODE-4930): Insufficiently strict BSON UTF8 validation
for (let i = 0; i < string.length; i++) {
if (string.charCodeAt(i) === 0xfffd) {
if (!validateUtf8(buffer, start, end)) {
throw new BSONError('Invalid UTF-8 string in BSON document');
}
break;
}
}
}
return string;
},

@@ -132,0 +151,0 @@

import { BSONError } from '../error';
import { tryLatin } from './latin';

@@ -175,4 +176,16 @@ type TextDecoder = {

toUTF8(uint8array: Uint8Array, start: number, end: number): string {
return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end));
toUTF8(uint8array: Uint8Array, start: number, end: number, fatal: boolean): string {
const basicLatin = end - start <= 20 ? tryLatin(uint8array, start, end) : null;
if (basicLatin != null) {
return basicLatin;
}
if (fatal) {
try {
return new TextDecoder('utf8', { fatal }).decode(uint8array.slice(start, end));
} catch (cause) {
throw new BSONError('Invalid UTF-8 string in BSON document', { cause });
}
}
return new TextDecoder('utf8', { fatal }).decode(uint8array.slice(start, end));
},

@@ -179,0 +192,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 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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc