-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw on invalid schema format #162
base: master
Are you sure you want to change the base?
Conversation
This could maybe be improved by just calling |
Very nice 👍 Unfortunately, I think that using the Do you think that this should be a major or patch release? 🤔 |
@@ -3,6 +3,28 @@ var cosmic = require('./fixtures/cosmic') | |||
var validator = require('../') | |||
var validatorRequire = require('../require') | |||
|
|||
tape('invalid schemas', function(t) { | |||
t.throws(function() { | |||
validater(Buffer.from('foo')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It throws because validater
is undefined due to a mistype (here and in all other checks below).
This test isn't testing anything.
@@ -110,6 +110,10 @@ var isMultipleOf = function(name, multipleOf) { | |||
} | |||
|
|||
var compile = function(schema, cache, root, reporter, opts) { | |||
if (Buffer.isBuffer(schema) || schema === null || (typeof schema !== 'string' && typeof schema !== 'object')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to be specific and check just for Buffer
.
Instead, only schema === true || schema === false || schema && Object.getPrototypeOf(schema) === Object.prototype
could be allowed here, like in @exodus/schemasafe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also that resolves the Buffer
concern from #162 (comment).
Prior to this change if your schema was in a Buffer, the validator would seem to work and pass all json as valid, but in reality it wasn't validating anything.