File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -838,6 +838,9 @@ export class BinMsg {
838
838
const promoteValues = options . promoteValues ?? this . opts . promoteValues ;
839
839
const promoteBuffers = options . promoteBuffers ?? this . opts . promoteBuffers ;
840
840
const bsonRegExp = options . bsonRegExp ?? this . opts . bsonRegExp ;
841
+ if ( options . validation && Object . keys ( options . validation . utf8 ) [ 0 ] !== 'writeErrors' ) {
842
+ throw new Error ( 'Can only toggle validation settings for writeErrors key' ) ;
843
+ }
841
844
const validation = options . validation ?? { utf8 : { writeErrors : false } } ;
842
845
843
846
// Set up the options
Original file line number Diff line number Diff line change @@ -71,6 +71,18 @@ const invalidUtf8InOtherKeyJSON = {
71
71
} ;
72
72
73
73
describe ( 'BinMsg' , function ( ) {
74
+ it ( 'should throw error if trying to toggle validation settings for keys other than writeErrors' , function ( ) {
75
+ const binMsgInvalidUtf8ErrorMsg = new BinMsg (
76
+ Buffer . alloc ( 0 ) ,
77
+ msgHeader ,
78
+ msgBodyInvalidUtf8WriteErrors
79
+ ) ;
80
+ expect ( ( ) => binMsgInvalidUtf8ErrorMsg . parse ( { validation : { utf8 : { n : false } } } ) ) . to . throw (
81
+ Error ,
82
+ 'Can only toggle validation settings for writeErrors key'
83
+ ) ;
84
+ } ) ;
85
+
74
86
it ( 'should not throw invalid utf8 error when validation disabled for writeErrors' , function ( ) {
75
87
const binMsgInvalidUtf8ErrorMsg = new BinMsg (
76
88
Buffer . alloc ( 0 ) ,
You can’t perform that action at this time.
0 commit comments