-
Type: New Feature
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: BSON
Description
Implement a new validation option in `DeserializeOptions` that allows all or a specified subset of top-level keys in a document to be excluded from strict utf-8 validation and instead apply the replacement behavior.
See design doc.
Acceptance criteria
- The new option should be called `validation` and accept an object with a `utf8` key that acts as follows:
- `utf8: false` disables all utf-8 validation on any field or subfield in the document
- `utf8: true` applies utf-8 validation to all fields in the document, and is the default setting
- `utf8:
{ [key: string]: true }
` disables utf-8 validation for all fields except the ones specified (or their subfields)
- `utf8:
{ [key: string]: false }
` disables utf-8 validation only for the specified fields (and their subfields)
- When an object is specified as the `utf8` validation rule, an error should be thrown if `Object.values(validation.utf8)`
- contains a mix of `true` and `false`
- is empty
- Tests should be added to ensure deserialization throws an error in all of the above cases when a non-excluded key contains invalid utf-8
- Tests should be added to ensure deserialization produces a document with replacement characters in the invalid utf-8 locations when an excluded key contains invalid utf-8
- is depended on by
-
NODE-3627 Getting "Invalid UTF-8 string in BSON document" instead on unique constraint error on bulkWrite.replaceOne
- Closed