Skip to content

Commit

Permalink
Fix exception when type is ['object', 'null'] and required is present…
Browse files Browse the repository at this point in the history
…. See acornejo#57
  • Loading branch information
GuillaumeDucret committed Nov 24, 2016
1 parent 525475c commit 9c722bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/jjv.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@
}
}

if (!Array.isArray(prop)) {
if (!prop) {
//skip
} else if (!Array.isArray(prop)) {
props = [];
objerrs = {};
for (p in prop)
Expand Down
19 changes: 18 additions & 1 deletion test/test-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ describe("basic functinal test", function () {
});
});


describe("nested objects", function () {
user_schema.definitions = {
location: {
Expand Down Expand Up @@ -308,6 +307,24 @@ describe("basic functinal test", function () {
expect(jjv.validate(selfReferentialSchema, manifest)).to.be.null;
});

describe("null objects", function() {
user_schema.properties.personal = {
type: ['object', 'null'],
properties: {
gender: {
type: 'string'
}
},
required: ['gender']
};

it("null", function () {
user_object.personal = null;
expect(jjv.validate('user', user_object)).to.be.null;
});

});

describe("useDefault", function() {
it("should clone default values", function() {
var defaults_schema = {
Expand Down

0 comments on commit 9c722bf

Please sign in to comment.