Skip to content

Commit 4eb5c31

Browse files
author
Ali Yousuf
committed
Changed the execution order of validations - conform, format, enum
1 parent 5626d2b commit 4eb5c31

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

lib/revalidator.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,6 @@
275275
}
276276
}
277277

278-
if (schema.format && options.validateFormats) {
279-
format = schema.format;
280-
281-
if (options.validateFormatExtensions) { spec = validate.formatExtensions[format] }
282-
if (!spec) { spec = validate.formats[format] }
283-
if (!spec) {
284-
if (options.validateFormatsStrict) {
285-
return error('format', property, value, schema, errors);
286-
}
287-
}
288-
else {
289-
if (!spec.test(value)) {
290-
return error('format', property, value, schema, errors);
291-
}
292-
}
293-
}
294-
295-
if (schema['enum'] && schema['enum'].indexOf(value) === -1) {
296-
error('enum', property, value, schema, errors);
297-
}
298-
299278
// Dependencies (see 5.8)
300279
if (typeof schema.dependencies === 'string' &&
301280
object[schema.dependencies] === undefined) {
@@ -317,8 +296,6 @@
317296
checkType(value, schema.type, function(err, type) {
318297
if (err) return error('type', property, typeof value, schema, errors);
319298

320-
constrain('conform', value, function (a, e) { return e(a, object) });
321-
322299
switch (type || (isArray(value) ? 'array' : typeof value)) {
323300
case 'string':
324301
constrain('allowEmpty', value, function (a, e) { return e ? e : a !== '' });
@@ -389,7 +366,30 @@
389366
}
390367
break;
391368
}
369+
370+
constrain('conform', value, function (a, e) { return e(a, object) });
392371
});
372+
373+
if (schema.format && options.validateFormats) {
374+
format = schema.format;
375+
376+
if (options.validateFormatExtensions) { spec = validate.formatExtensions[format] }
377+
if (!spec) { spec = validate.formats[format] }
378+
if (!spec) {
379+
if (options.validateFormatsStrict) {
380+
return error('format', property, value, schema, errors);
381+
}
382+
}
383+
else {
384+
if (!spec.test(value)) {
385+
return error('format', property, value, schema, errors);
386+
}
387+
}
388+
}
389+
390+
if (schema['enum'] && schema['enum'].indexOf(value) === -1) {
391+
error('enum', property, value, schema, errors);
392+
}
393393
}
394394

395395
function checkType(val, type, callback) {

0 commit comments

Comments
 (0)