不要怂,就是干,撸起袖子干!

Commit 00d1581f by Jan Aagaard Meier

Merge pull request #5599 from kylehotchkiss/5365-validator-cast-as-strings

Cast value as string to pass new Validator.js string requirement
2 parents f42d487f 46c2f566
Showing with 3 additions and 1 deletions
...@@ -254,12 +254,14 @@ InstanceValidator.prototype._invokeCustomValidator = Promise.method(function(val ...@@ -254,12 +254,14 @@ InstanceValidator.prototype._invokeCustomValidator = Promise.method(function(val
*/ */
InstanceValidator.prototype._invokeBuiltinValidator = Promise.method(function(value, test, validatorType, field) { InstanceValidator.prototype._invokeBuiltinValidator = Promise.method(function(value, test, validatorType, field) {
var self = this; var self = this;
// Cast value as string to pass new Validator.js string requirement
var valueString = String(value);
// check if Validator knows that kind of validation test // check if Validator knows that kind of validation test
if (typeof validator[validatorType] !== 'function') { if (typeof validator[validatorType] !== 'function') {
throw new Error('Invalid validator function: ' + validatorType); throw new Error('Invalid validator function: ' + validatorType);
} }
var validatorArgs = self._extractValidatorArgs(test, validatorType, field); var validatorArgs = self._extractValidatorArgs(test, validatorType, field);
if (!validator[validatorType].apply(validator, [value].concat(validatorArgs))) { if (!validator[validatorType].apply(validator, [valueString].concat(validatorArgs))) {
// extract the error msg // extract the error msg
throw new Error(test.msg || 'Validation ' + validatorType + ' failed'); throw new Error(test.msg || 'Validation ' + validatorType + ' failed');
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!