Comparing version 4.3.1 to 4.4.0
@@ -30,11 +30,12 @@ // Load modules | ||
var format = Hoek.reach(localized, this.type) || Hoek.reach(Language.errors, this.type); | ||
var hasKey = false; | ||
var message = format.replace(/\{\{\s*([^\s}]+?)\s*\}\}/ig, function (match, name) { | ||
var hasKey = /\{\{\!?key\}\}/.test(format); | ||
format = (hasKey ? format : '{{!key}} ' + format); | ||
var message = format.replace(/\{\{(\!?)([^}]+)\}\}/g, function ($0, isSecure, name) { | ||
hasKey = hasKey || name === 'key'; | ||
var value = Hoek.reach(self.context, name); | ||
return Array.isArray(value) ? value.join(', ') : value.toString(); | ||
var normalized = Array.isArray(value) ? value.join(', ') : value.toString(); | ||
return (isSecure ? Hoek.escapeHtml(normalized) : normalized); | ||
}); | ||
return hasKey ? message : this.context.key + ' ' + message; | ||
return message; | ||
}; | ||
@@ -74,2 +75,3 @@ | ||
var error = new Error(message); | ||
error.name = 'ValidationError'; | ||
error.details = details; | ||
@@ -76,0 +78,0 @@ error._object = object; |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "4.3.1", | ||
"version": "4.4.0", | ||
"repository": "git://github.com/spumko/joi", | ||
@@ -6,0 +6,0 @@ "main": "index", |
@@ -74,2 +74,3 @@ // Load modules | ||
expect(err).to.exist; | ||
expect(err.name).to.equal('ValidationError'); | ||
expect(err.message).to.equal('value 11. required 7. xor 7. email 19. date 18. alphanum 16. min 14. max 15. notEmpty 3. notEmpty 13'); | ||
@@ -89,2 +90,20 @@ done(); | ||
it('escapes unsafe keys', function (done) { | ||
var schema = { | ||
'a()': Joi.number() | ||
}; | ||
Joi.validate({ 'a()': 'x' }, schema, function (err, value) { | ||
expect(err.message).to.equal('a() must be a number'); | ||
Joi.validate({ 'b()': 'x' }, schema, function (err, value) { | ||
expect(err.message).to.equal('b() is not allowed'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('returns error type in validation error', function (done) { | ||
@@ -91,0 +110,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
460762
7225
10