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: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: node_js
before_install:
- curl --location http://git.io/1OcIZA | bash -s
node_js:
- "0.8"
- "0.10"
Expand Down
10 changes: 8 additions & 2 deletions lib/revalidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@
if (value === undefined) {
if (schema.required && schema.type !== 'any') {
return error('required', property, undefined, schema, errors);
} else if (schema.default !== undefined) {
object[property] = schema.default;
return;
} else {
return;
}
Expand All @@ -275,7 +278,7 @@
}
}

if (schema.format && options.validateFormats) {
if (schema.format && options.validateFormats && !(value === null && schema.type.indexOf('null') !== -1)) {
format = schema.format;

if (options.validateFormatExtensions) { spec = validate.formatExtensions[format] }
Expand All @@ -293,7 +296,10 @@
}

if (schema['enum'] && schema['enum'].indexOf(value) === -1) {
error('enum', property, value, schema, errors);
// Support allowEmpty and allow null if it's in the types (issue #84)
if (!(schema.type.indexOf('string') !== -1 && schema.allowEmpty && value === '') &&
!(schema.type.indexOf('null') !== -1 && value === null))
error('enum', property, value, schema, errors);
}

// Dependencies (see 5.8)
Expand Down