-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Providing a function for the replaceWith
option only works if the function (when converted to a string) does not contain a "."
character. This is due to the regex test here:
if(!(TEST_REGEX.test(options.replaceWith))) {
replaceWith = options.replaceWith;
}
Recommend allowing any function for replaceWith
by changing that block to:
if(typeof options.replaceWith === 'function' || !(TEST_REGEX.test(options.replaceWith))) {
replaceWith = options.replaceWith;
}
By doing this, users can be more specific with their replace value, e.g.:
mongoSanitize({ replaceWith: (match) => {
switch (match) {
case '$':
return '_dollar_';
case '.': // this line currently triggers the `TEST_REGEX.test(options.replaceWith)`
return '_dot_';
default:
return '_';
}
} })
Metadata
Metadata
Assignees
Labels
No labels