Skip to content

Commit

Permalink
Change how Object casting happens to always return {} if type isn't o…
Browse files Browse the repository at this point in the history
…bject.
  • Loading branch information
Dom Harrington committed Aug 23, 2012
1 parent 9d2707b commit 272d00d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/schemata.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ module.exports = function(schema) {
}
return value.toString && value.toString();
case Object:
return (value === '' || value === null || value === undefined) ? {} : value;
// typeof null === 'object', so the extra check is needed for null
return (typeof value !== 'object' || value === null) ? {} : value;
case Date:
return (value === '' || value === null || value === undefined) ? null : (value instanceof Date ? value : new Date(value));
case Array:
Expand Down
2 changes: 1 addition & 1 deletion test/schemata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe('schemata', function() {

it('converts object correctly', function() {
var schema = createArraySchema();
[null, ''].forEach(function(value) {
[null, '', 'hello', [], undefined].forEach(function(value) {
Object.keys(schema.castProperty(Object, value)).should.have.lengthOf(0);
});
[{a:'b'}].forEach(function(value) {
Expand Down

0 comments on commit 272d00d

Please sign in to comment.