Skip to content

Commit 3c041f4

Browse files
authored
revert(NODE-3784): Add enableUtf8Validation option" (#3073)
1 parent 9237d72 commit 3c041f4

File tree

11 files changed

+68
-222
lines changed

11 files changed

+68
-222
lines changed

src/bson.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ export interface BSONSerializeOptions
5555
> {
5656
/** Return BSON filled buffers from operations */
5757
raw?: boolean;
58-
59-
/** Enable utf8 validation when deserializing BSON documents. Defaults to true. */
60-
enableUtf8Validation?: boolean;
6158
}
6259

6360
export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSerializeOptions {
@@ -69,8 +66,7 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
6966
serializeFunctions,
7067
ignoreUndefined,
7168
bsonRegExp,
72-
raw,
73-
enableUtf8Validation
69+
raw
7470
} = options;
7571
return {
7672
fieldsAsRaw,
@@ -80,8 +76,7 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
8076
serializeFunctions,
8177
ignoreUndefined,
8278
bsonRegExp,
83-
raw,
84-
enableUtf8Validation
79+
raw
8580
};
8681
}
8782

@@ -104,8 +99,6 @@ export function resolveBSONOptions(
10499
ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false,
105100
bsonRegExp: options?.bsonRegExp ?? parentOptions?.bsonRegExp ?? false,
106101
serializeFunctions: options?.serializeFunctions ?? parentOptions?.serializeFunctions ?? false,
107-
fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {},
108-
enableUtf8Validation:
109-
options?.enableUtf8Validation ?? parentOptions?.enableUtf8Validation ?? true
102+
fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {}
110103
};
111104
}

src/cmap/commands.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ export interface MessageHeader {
469469
export interface OpResponseOptions extends BSONSerializeOptions {
470470
raw?: boolean;
471471
documentsReturnedIn?: string | null;
472+
// For now we use this internally to only prevent writeErrors from crashing the driver
473+
validation?: { utf8: { writeErrors: boolean } };
472474
}
473475

474476
/** @internal */
@@ -837,7 +839,7 @@ export class BinMsg {
837839
const promoteValues = options.promoteValues ?? this.opts.promoteValues;
838840
const promoteBuffers = options.promoteBuffers ?? this.opts.promoteBuffers;
839841
const bsonRegExp = options.bsonRegExp ?? this.opts.bsonRegExp;
840-
const validation = this.parseBsonSerializationOptions(options);
842+
const validation = options.validation ?? { utf8: { writeErrors: false } };
841843

842844
// Set up the options
843845
const bsonOptions: BSONSerializeOptions = {
@@ -874,14 +876,4 @@ export class BinMsg {
874876

875877
this.parsed = true;
876878
}
877-
878-
parseBsonSerializationOptions({ enableUtf8Validation }: BSONSerializeOptions): {
879-
utf8: { writeErrors: false } | false;
880-
} {
881-
if (enableUtf8Validation === false) {
882-
return { utf8: false };
883-
}
884-
885-
return { utf8: { writeErrors: false } };
886-
}
887879
}

src/cmap/connection.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,6 @@ function write(
787787
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
788788
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
789789
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
790-
enableUtf8Validation:
791-
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true,
792790
raw: typeof options.raw === 'boolean' ? options.raw : false,
793791
started: 0
794792
};

src/cmap/wire_protocol/shared.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export function applyCommonQueryOptions(
4545
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
4646
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
4747
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
48-
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
49-
enableUtf8Validation:
50-
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
48+
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false
5149
});
5250

5351
if (options.session) {

src/connection_string.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ export const OPTIONS = {
688688
});
689689
}
690690
},
691-
enableUtf8Validation: { type: 'boolean', default: true },
692691
family: {
693692
transform({ name, values: [value] }): 4 | 6 {
694693
const transformValue = getInt(name, value);

src/db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ const DB_OPTIONS_ALLOW_LIST = [
7373
'promoteBuffers',
7474
'promoteLongs',
7575
'bsonRegExp',
76-
'enableUtf8Validation',
7776
'promoteValues',
7877
'compression',
7978
'retryWrites'

src/operations/create_collection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
2727
'promoteBuffers',
2828
'bsonRegExp',
2929
'serializeFunctions',
30-
'ignoreUndefined',
31-
'enableUtf8Validation'
30+
'ignoreUndefined'
3231
]);
3332

3433
/** @public

src/operations/map_reduce.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const exclusionList = [
3333
'bsonRegExp',
3434
'serializeFunctions',
3535
'ignoreUndefined',
36-
'enableUtf8Validation',
3736
'scope' // this option is reformatted thus exclude the original
3837
];
3938

test/functional/cmap/commands.test.ts

Lines changed: 0 additions & 122 deletions
This file was deleted.

test/types/bson.test-d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type PermittedBSONOptionKeys =
2121
| 'promoteValues'
2222
| 'bsonRegExp'
2323
| 'fieldsAsRaw'
24-
| 'enableUtf8Validation'
2524
| 'raw';
2625

2726
const keys = null as unknown as PermittedBSONOptionKeys;

0 commit comments

Comments
 (0)