Comparing version 4.6.0 to 4.6.1
@@ -42,2 +42,8 @@ // Load modules | ||
if (typeof value === 'string' && | ||
/^\d+$/.test(value)) { | ||
value = parseInt(value, 10); | ||
} | ||
var date = new Date(value); | ||
@@ -85,2 +91,2 @@ if (!isNaN(date.getTime())) { | ||
module.exports = new internals.Date(); | ||
module.exports = new internals.Date(); |
@@ -78,2 +78,6 @@ // Load modules | ||
if (target[item.from] === undefined) { | ||
continue; | ||
} | ||
if (!item.options.multiple && | ||
@@ -121,3 +125,5 @@ renamed[item.to]) { | ||
if (!this._inner.children) { // null allows any keys | ||
if (!this._inner.children && // null allows any keys | ||
!this._inner.patterns.length) { | ||
return finish(); | ||
@@ -129,20 +135,22 @@ } | ||
for (var i = 0, il = this._inner.children.length; i < il; ++i) { | ||
var child = this._inner.children[i]; | ||
var key = child.key; | ||
var item = target[key]; | ||
if (this._inner.children) { | ||
for (var i = 0, il = this._inner.children.length; i < il; ++i) { | ||
var child = this._inner.children[i]; | ||
var key = child.key; | ||
var item = target[key]; | ||
delete unprocessed[key]; | ||
delete unprocessed[key]; | ||
var localState = { key: key, path: (state.path ? state.path + '.' : '') + key, parent: target, reference: state.reference }; | ||
var result = child.schema._validate(item, localState, options); | ||
if (result.errors) { | ||
errors = errors.concat(result.errors); | ||
if (options.abortEarly) { | ||
return finish(); | ||
var localState = { key: key, path: (state.path ? state.path + '.' : '') + key, parent: target, reference: state.reference }; | ||
var result = child.schema._validate(item, localState, options); | ||
if (result.errors) { | ||
errors = errors.concat(result.errors); | ||
if (options.abortEarly) { | ||
return finish(); | ||
} | ||
} | ||
} | ||
if (result.value !== undefined) { | ||
target[key] = result.value; | ||
if (result.value !== undefined) { | ||
target[key] = result.value; | ||
} | ||
} | ||
@@ -149,0 +157,0 @@ } |
@@ -41,3 +41,3 @@ // Load modules | ||
value: value, | ||
errors: (value && typeof value === 'string') ? null : Errors.create('string.base', null, state, options) | ||
errors: (typeof value === 'string') ? null : Errors.create('string.base', null, state, options) | ||
}; | ||
@@ -262,2 +262,2 @@ }; | ||
module.exports = new internals.String(); | ||
module.exports = new internals.String(); |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "4.6.0", | ||
"version": "4.6.1", | ||
"repository": "git://github.com/spumko/joi", | ||
@@ -6,0 +6,0 @@ "main": "index", |
@@ -300,3 +300,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a> | ||
### `any.forbidden()` | ||
#### `any.forbidden()` | ||
@@ -303,0 +303,0 @@ Marks a key as forbidden which will not allow any value except `undefined`. Used to explicitly forbid keys. |
@@ -62,2 +62,15 @@ // Load modules | ||
it('validates millisecond date as a string', function (done) { | ||
var now = new Date(); | ||
var mili = now.getTime(); | ||
Joi.date().validate(mili.toString(), function (err, value) { | ||
expect(err).to.not.exist; | ||
expect(value).to.be.eql(now); | ||
done(); | ||
}); | ||
}); | ||
describe('#validate', function () { | ||
@@ -64,0 +77,0 @@ |
@@ -75,3 +75,3 @@ // Load modules | ||
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'); | ||
expect(err.message).to.equal('value 11. required 7. xor 7. email 19. date 18. alphanum 16. min 14. max 15. notEmpty 3'); | ||
done(); | ||
@@ -234,3 +234,3 @@ }); | ||
}; | ||
Joi.validate({ x: true }, schema, function (err, value) { | ||
@@ -237,0 +237,0 @@ |
@@ -556,2 +556,19 @@ // Load modules | ||
}); | ||
it('should not create new keys when they key in question does not exist', function (done) { | ||
var schema = Joi.object().rename('b', '_b'); | ||
var input = { | ||
a: 'something' | ||
}; | ||
schema.validate(input, function (err, value) { | ||
expect(err).to.not.exist; | ||
expect(value).to.have.keys(['a']); | ||
expect(value.a).to.equal('something'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -663,2 +680,14 @@ | ||
}); | ||
it('errors when using a pattern on empty schema with unknown(false) and pattern mismatch', function (done) { | ||
var schema = Joi.object().pattern(/\d/, Joi.number()).unknown(false); | ||
Joi.validate({ a: 5 }, schema, { abortEarly: false }, function (err, value) { | ||
expect(err).to.exist; | ||
expect(err.message).to.equal('a is not allowed'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -883,2 +912,1 @@ | ||
}); | ||
@@ -340,2 +340,13 @@ // Load modules | ||
it('removes leading and trailing whitespace before validation', function (done) { | ||
var schema = Joi.string().trim().allow(''); | ||
schema.validate(' ', function (err, value) { | ||
expect(err).to.not.exist; | ||
expect(value).to.equal(''); | ||
done(); | ||
}); | ||
}); | ||
it('should work in combination with min', function (done) { | ||
@@ -342,0 +353,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
463825
7296