Skip to content

Commit 1059175

Browse files
Merge branch 'main' into uri-validate-less
2 parents 154e2ad + 833eaa4 commit 1059175

File tree

17 files changed

+155
-255
lines changed

17 files changed

+155
-255
lines changed

.github/workflows/build_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build and commit docs
22

33
on:
44
push:
5-
branches: [main]
5+
branches: ['main']
66

77
permissions:
88
contents: write

.github/workflows/release-5.x.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [5.x]
3+
branches: ['5.x']
44
workflow_dispatch: {}
55

66
permissions:
@@ -19,7 +19,7 @@ jobs:
1919
- id: release
2020
uses: googleapis/release-please-action@v4
2121
with:
22-
target-branch: 5.x
22+
target-branch: '5.x'
2323

2424
build:
2525
needs: [release_please]
@@ -37,6 +37,8 @@ jobs:
3737
runs-on: ubuntu-latest
3838
steps:
3939
- uses: actions/checkout@v4
40+
with:
41+
ref: '5.x'
4042

4143
- name: Install Node and dependencies
4244
uses: mongodb-labs/drivers-github-tools/node/setup@v2
@@ -75,7 +77,7 @@ jobs:
7577
with:
7678
release_version: ${{ env.package_version }}
7779
product_name: mongodb
78-
sarif_report_target_ref: 5.x
80+
sarif_report_target_ref: '5.x'
7981
third_party_dependency_tool: n/a
8082
dist_filenames: artifacts/*
8183
token: ${{ github.token }}
@@ -95,6 +97,8 @@ jobs:
9597
runs-on: ubuntu-latest
9698
steps:
9799
- uses: actions/checkout@v4
100+
with:
101+
ref: '5.x'
98102

99103
- name: Install Node and dependencies
100104
uses: mongodb-labs/drivers-github-tools/node/setup@v2

.github/workflows/release-6.8.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [6.8]
3+
branches: ['6.8']
44
workflow_dispatch: {}
55

66
permissions:
@@ -19,11 +19,11 @@ jobs:
1919
- id: release
2020
uses: googleapis/release-please-action@v4
2121
with:
22-
target-branch: 6.8
22+
target-branch: '6.8'
2323

2424
build:
2525
needs: [release_please]
26-
name: "Perform any build or bundling steps, as necessary."
26+
name: 'Perform any build or bundling steps, as necessary.'
2727
uses: ./.github/workflows/build.yml
2828

2929
ssdlc:
@@ -37,6 +37,8 @@ jobs:
3737
runs-on: ubuntu-latest
3838
steps:
3939
- uses: actions/checkout@v4
40+
with:
41+
ref: '6.8'
4042

4143
- name: Install Node and dependencies
4244
uses: mongodb-labs/drivers-github-tools/node/setup@v2
@@ -75,7 +77,7 @@ jobs:
7577
with:
7678
release_version: ${{ env.package_version }}
7779
product_name: mongodb
78-
sarif_report_target_ref: 6.8
80+
sarif_report_target_ref: '6.8'
7981
third_party_dependency_tool: n/a
8082
dist_filenames: artifacts/*
8183
token: ${{ github.token }}
@@ -95,6 +97,8 @@ jobs:
9597
runs-on: ubuntu-latest
9698
steps:
9799
- uses: actions/checkout@v4
100+
with:
101+
ref: '6.8'
98102

99103
- name: Install Node and dependencies
100104
uses: mongodb-labs/drivers-github-tools/node/setup@v2

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [main]
3+
branches: ['main']
44
workflow_dispatch: {}
55

66
permissions:
@@ -19,7 +19,7 @@ jobs:
1919
- id: release
2020
uses: googleapis/release-please-action@v4
2121
with:
22-
target-branch: main
22+
target-branch: 'main'
2323

2424
build:
2525
needs: [release_please]
@@ -75,7 +75,7 @@ jobs:
7575
with:
7676
release_version: ${{ env.package_version }}
7777
product_name: mongodb
78-
sarif_report_target_ref: main
78+
sarif_report_target_ref: 'main'
7979
third_party_dependency_tool: n/a
8080
dist_filenames: artifacts/*
8181
token: ${{ github.token }}

src/bson.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,14 @@ export function resolveBSONOptions(
132132
options?.enableUtf8Validation ?? parentOptions?.enableUtf8Validation ?? true
133133
};
134134
}
135+
136+
/** @internal */
137+
export function parseUtf8ValidationOption(options?: { enableUtf8Validation?: boolean }): {
138+
utf8: { writeErrors: false } | false;
139+
} {
140+
const enableUtf8Validation = options?.enableUtf8Validation;
141+
if (enableUtf8Validation === false) {
142+
return { utf8: false };
143+
}
144+
return { utf8: { writeErrors: false } };
145+
}

src/cmap/connect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export async function prepareHandshakeDocument(
249249

250250
/** @public */
251251
export const LEGAL_TLS_SOCKET_OPTIONS = [
252+
'allowPartialTrustChain',
252253
'ALPNProtocols',
253254
'ca',
254255
'cert',

src/cmap/connection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type DeserializeOptions } from 'bson';
12
import { type Readable, Transform, type TransformCallback } from 'stream';
23
import { clearTimeout, setTimeout } from 'timers';
34

@@ -487,7 +488,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
487488

488489
// If `documentsReturnedIn` not set or raw is not enabled, use input bson options
489490
// Otherwise, support raw flag. Raw only works for cursors that hardcode firstBatch/nextBatch fields
490-
const bsonOptions =
491+
const bsonOptions: DeserializeOptions =
491492
options.documentsReturnedIn == null || !options.raw
492493
? options
493494
: {

src/cmap/wire_protocol/on_demand/document.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { type DeserializeOptions } from 'bson';
2+
13
import {
24
Binary,
35
type BSONElement,
46
BSONError,
5-
type BSONSerializeOptions,
67
BSONType,
78
deserialize,
89
getBigInt64LE,
910
getFloat64LE,
1011
getInt32LE,
1112
ObjectId,
1213
parseToElementsToArray,
13-
pluckBSONSerializeOptions,
1414
Timestamp,
1515
toUTF8
1616
} from '../../../bson';
@@ -44,6 +44,14 @@ export type JSTypeOf = {
4444
/** @internal */
4545
type CachedBSONElement = { element: BSONElement; value: any | undefined };
4646

47+
/**
48+
* @internal
49+
*
50+
* Options for `OnDemandDocument.toObject()`. Validation is required to ensure
51+
* that callers provide utf8 validation options. */
52+
export type OnDemandDocumentDeserializeOptions = Omit<DeserializeOptions, 'validation'> &
53+
Required<Pick<DeserializeOptions, 'validation'>>;
54+
4755
/** @internal */
4856
export class OnDemandDocument {
4957
/**
@@ -330,24 +338,12 @@ export class OnDemandDocument {
330338
* Deserialize this object, DOES NOT cache result so avoid multiple invocations
331339
* @param options - BSON deserialization options
332340
*/
333-
public toObject(options?: BSONSerializeOptions): Record<string, any> {
334-
const exactBSONOptions = {
335-
...pluckBSONSerializeOptions(options ?? {}),
336-
validation: this.parseBsonSerializationOptions(options),
341+
public toObject(options?: OnDemandDocumentDeserializeOptions): Record<string, any> {
342+
return deserialize(this.bson, {
343+
...options,
337344
index: this.offset,
338345
allowObjectSmallerThanBufferSize: true
339-
};
340-
return deserialize(this.bson, exactBSONOptions);
341-
}
342-
343-
private parseBsonSerializationOptions(options?: { enableUtf8Validation?: boolean }): {
344-
utf8: { writeErrors: false } | false;
345-
} {
346-
const enableUtf8Validation = options?.enableUtf8Validation;
347-
if (enableUtf8Validation === false) {
348-
return { utf8: false };
349-
}
350-
return { utf8: { writeErrors: false } };
346+
});
351347
}
352348

353349
/** Returns this document's bytes only */

src/cmap/wire_protocol/responses.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
import { type DeserializeOptions } from 'bson';
2+
13
import {
24
type BSONElement,
35
type BSONSerializeOptions,
46
BSONType,
57
type Document,
68
Long,
79
parseToElementsToArray,
10+
parseUtf8ValidationOption,
11+
pluckBSONSerializeOptions,
812
type Timestamp
913
} from '../../bson';
1014
import { MongoUnexpectedServerResponseError } from '../../error';
1115
import { type ClusterTime } from '../../sdam/common';
1216
import { decorateDecryptionResult, ns } from '../../utils';
13-
import { type JSTypeOf, OnDemandDocument } from './on_demand/document';
17+
import {
18+
type JSTypeOf,
19+
OnDemandDocument,
20+
type OnDemandDocumentDeserializeOptions
21+
} from './on_demand/document';
1422

1523
// eslint-disable-next-line no-restricted-syntax
1624
const enum BSONElementOffset {
@@ -112,7 +120,8 @@ export class MongoDBResponse extends OnDemandDocument {
112120
this.get('recoveryToken', BSONType.object)?.toObject({
113121
promoteValues: false,
114122
promoteLongs: false,
115-
promoteBuffers: false
123+
promoteBuffers: false,
124+
validation: { utf8: true }
116125
}) ?? null
117126
);
118127
}
@@ -165,6 +174,14 @@ export class MongoDBResponse extends OnDemandDocument {
165174
}
166175
return this.clusterTime ?? null;
167176
}
177+
178+
public override toObject(options?: BSONSerializeOptions): Record<string, any> {
179+
const exactBSONOptions = {
180+
...pluckBSONSerializeOptions(options ?? {}),
181+
validation: parseUtf8ValidationOption(options)
182+
};
183+
return super.toObject(exactBSONOptions);
184+
}
168185
}
169186

170187
/** @internal */
@@ -248,12 +265,13 @@ export class CursorResponse extends MongoDBResponse {
248265
this.cursor.get('postBatchResumeToken', BSONType.object)?.toObject({
249266
promoteValues: false,
250267
promoteLongs: false,
251-
promoteBuffers: false
268+
promoteBuffers: false,
269+
validation: { utf8: true }
252270
}) ?? null
253271
);
254272
}
255273

256-
public shift(options?: BSONSerializeOptions): any {
274+
public shift(options: OnDemandDocumentDeserializeOptions): any {
257275
if (this.iterated >= this.batchSize) {
258276
return null;
259277
}
@@ -305,7 +323,7 @@ export class ExplainedCursorResponse extends CursorResponse {
305323
return this._length;
306324
}
307325

308-
override shift(options?: BSONSerializeOptions | undefined) {
326+
override shift(options?: DeserializeOptions) {
309327
if (this._length === 0) return null;
310328
this._length -= 1;
311329
return this.toObject(options);

src/connection_string.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,8 @@ export const OPTIONS = {
12211221
// Custom types for modifying core behavior
12221222
connectionType: { type: 'any' },
12231223
srvPoller: { type: 'any' },
1224-
// Accepted NodeJS Options
1224+
// Accepted Node.js Options
1225+
allowPartialTrustChain: { type: 'any' },
12251226
minDHSize: { type: 'any' },
12261227
pskCallback: { type: 'any' },
12271228
secureContext: { type: 'any' },

0 commit comments

Comments
 (0)