Skip to content

Commit

Permalink
revert(NODE-3784): Add enableUtf8Validation option" (#3073)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Dec 9, 2021
1 parent 9237d72 commit 3c041f4
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 222 deletions.
13 changes: 3 additions & 10 deletions src/bson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ export interface BSONSerializeOptions
> {
/** Return BSON filled buffers from operations */
raw?: boolean;

/** Enable utf8 validation when deserializing BSON documents. Defaults to true. */
enableUtf8Validation?: boolean;
}

export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSerializeOptions {
Expand All @@ -69,8 +66,7 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
serializeFunctions,
ignoreUndefined,
bsonRegExp,
raw,
enableUtf8Validation
raw
} = options;
return {
fieldsAsRaw,
Expand All @@ -80,8 +76,7 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
serializeFunctions,
ignoreUndefined,
bsonRegExp,
raw,
enableUtf8Validation
raw
};
}

Expand All @@ -104,8 +99,6 @@ export function resolveBSONOptions(
ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false,
bsonRegExp: options?.bsonRegExp ?? parentOptions?.bsonRegExp ?? false,
serializeFunctions: options?.serializeFunctions ?? parentOptions?.serializeFunctions ?? false,
fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {},
enableUtf8Validation:
options?.enableUtf8Validation ?? parentOptions?.enableUtf8Validation ?? true
fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {}
};
}
14 changes: 3 additions & 11 deletions src/cmap/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ export interface MessageHeader {
export interface OpResponseOptions extends BSONSerializeOptions {
raw?: boolean;
documentsReturnedIn?: string | null;
// For now we use this internally to only prevent writeErrors from crashing the driver
validation?: { utf8: { writeErrors: boolean } };
}

/** @internal */
Expand Down Expand Up @@ -837,7 +839,7 @@ export class BinMsg {
const promoteValues = options.promoteValues ?? this.opts.promoteValues;
const promoteBuffers = options.promoteBuffers ?? this.opts.promoteBuffers;
const bsonRegExp = options.bsonRegExp ?? this.opts.bsonRegExp;
const validation = this.parseBsonSerializationOptions(options);
const validation = options.validation ?? { utf8: { writeErrors: false } };

// Set up the options
const bsonOptions: BSONSerializeOptions = {
Expand Down Expand Up @@ -874,14 +876,4 @@ export class BinMsg {

this.parsed = true;
}

parseBsonSerializationOptions({ enableUtf8Validation }: BSONSerializeOptions): {
utf8: { writeErrors: false } | false;
} {
if (enableUtf8Validation === false) {
return { utf8: false };
}

return { utf8: { writeErrors: false } };
}
}
2 changes: 0 additions & 2 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,6 @@ function write(
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
enableUtf8Validation:
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true,
raw: typeof options.raw === 'boolean' ? options.raw : false,
started: 0
};
Expand Down
4 changes: 1 addition & 3 deletions src/cmap/wire_protocol/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export function applyCommonQueryOptions(
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
enableUtf8Validation:
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false
});

if (options.session) {
Expand Down
1 change: 0 additions & 1 deletion src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ export const OPTIONS = {
});
}
},
enableUtf8Validation: { type: 'boolean', default: true },
family: {
transform({ name, values: [value] }): 4 | 6 {
const transformValue = getInt(name, value);
Expand Down
1 change: 0 additions & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const DB_OPTIONS_ALLOW_LIST = [
'promoteBuffers',
'promoteLongs',
'bsonRegExp',
'enableUtf8Validation',
'promoteValues',
'compression',
'retryWrites'
Expand Down
3 changes: 1 addition & 2 deletions src/operations/create_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
'promoteBuffers',
'bsonRegExp',
'serializeFunctions',
'ignoreUndefined',
'enableUtf8Validation'
'ignoreUndefined'
]);

/** @public
Expand Down
1 change: 0 additions & 1 deletion src/operations/map_reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const exclusionList = [
'bsonRegExp',
'serializeFunctions',
'ignoreUndefined',
'enableUtf8Validation',
'scope' // this option is reformatted thus exclude the original
];

Expand Down
122 changes: 0 additions & 122 deletions test/functional/cmap/commands.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/types/bson.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type PermittedBSONOptionKeys =
| 'promoteValues'
| 'bsonRegExp'
| 'fieldsAsRaw'
| 'enableUtf8Validation'
| 'raw';

const keys = null as unknown as PermittedBSONOptionKeys;
Expand Down
Loading

0 comments on commit 3c041f4

Please sign in to comment.