Skip to content

Commit 491b9cc

Browse files
committed
fix(schematype): handle passing message function to SchemaType#validate() as positional arg
Fix #8360
1 parent 253e054 commit 491b9cc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/schematype.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,21 +676,24 @@ SchemaType.prototype.get = function(fn) {
676676
SchemaType.prototype.validate = function(obj, message, type) {
677677
if (typeof obj === 'function' || obj && utils.getFunctionName(obj.constructor) === 'RegExp') {
678678
let properties;
679-
if (message instanceof Object && !type) {
679+
if (typeof message === 'function') {
680+
properties = { validator: obj, message: message };
681+
properties.type = type || 'user defined';
682+
} else if (message instanceof Object && !type) {
680683
properties = utils.clone(message);
681684
if (!properties.message) {
682685
properties.message = properties.msg;
683686
}
684687
properties.validator = obj;
685688
properties.type = properties.type || 'user defined';
686689
} else {
687-
if (!message) {
690+
if (message == null) {
688691
message = MongooseError.messages.general.default;
689692
}
690693
if (!type) {
691694
type = 'user defined';
692695
}
693-
properties = {message: message, type: type, validator: obj};
696+
properties = { message: message, type: type, validator: obj };
694697
}
695698

696699
if (properties.isAsync) {

0 commit comments

Comments
 (0)