Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ValidatorContext.prototype.validateType = function validateType(data, schema) {
dataType = "array";
}
var allowedTypes = schema.type;
if (typeof allowedTypes !== "object") {
if (!Array.isArray(allowedTypes)) {
allowedTypes = [allowedTypes];
}

Expand Down
3 changes: 2 additions & 1 deletion source/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts,
while (this.scanned.length) {
var item = this.scanned.pop();
delete item[this.validatedSchemasKey];
delete item[this.validationErrorsKey];
}
this.scannedFrozen = [];
this.scannedFrozenSchemas = [];
Expand All @@ -309,7 +310,7 @@ ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts,

if (scannedFrozenSchemaIndex !== null) {
this.scannedFrozenValidationErrors[frozenIndex][scannedFrozenSchemaIndex] = this.errors.slice(startErrorCount);
} else if (scannedSchemasIndex !== null) {
} else if (scannedSchemasIndex !== null && !topLevel) {
data[this.validationErrorsKey][scannedSchemasIndex] = this.errors.slice(startErrorCount);
}

Expand Down
7 changes: 7 additions & 0 deletions test/all_concat.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/all_concat.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/tests/01 - Any types/01 - type.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ describe("Any types 01", function () {
var valid = tv4.validate(data, schema);
assert.isTrue(valid);
});

it("doesn't crash on invalid type", function () {
var data = null;
var schema = {"type": {"foo": "bar"}};
var valid = tv4.validate(data, schema);
assert.isFalse(valid);
});
});
5 changes: 3 additions & 2 deletions tv4.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts,
while (this.scanned.length) {
var item = this.scanned.pop();
delete item[this.validatedSchemasKey];
delete item[this.validationErrorsKey];
}
this.scannedFrozen = [];
this.scannedFrozenSchemas = [];
Expand All @@ -629,7 +630,7 @@ ValidatorContext.prototype.validateAll = function (data, schema, dataPathParts,

if (scannedFrozenSchemaIndex !== null) {
this.scannedFrozenValidationErrors[frozenIndex][scannedFrozenSchemaIndex] = this.errors.slice(startErrorCount);
} else if (scannedSchemasIndex !== null) {
} else if (scannedSchemasIndex !== null && !topLevel) {
data[this.validationErrorsKey][scannedSchemasIndex] = this.errors.slice(startErrorCount);
}

Expand Down Expand Up @@ -738,7 +739,7 @@ ValidatorContext.prototype.validateType = function validateType(data, schema) {
dataType = "array";
}
var allowedTypes = schema.type;
if (typeof allowedTypes !== "object") {
if (!Array.isArray(allowedTypes)) {
allowedTypes = [allowedTypes];
}

Expand Down
2 changes: 1 addition & 1 deletion tv4.min.js

Large diffs are not rendered by default.