diff --git a/.travis.yml b/.travis.yml index 04d6dd9..a008924 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: node_js +before_install: + - curl --location http://git.io/1OcIZA | bash -s node_js: - "0.8" - "0.10" diff --git a/lib/revalidator.js b/lib/revalidator.js index 0c0160f..c200661 100644 --- a/lib/revalidator.js +++ b/lib/revalidator.js @@ -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; } @@ -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] } @@ -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)