Skip to content

Conversation

@watson
Copy link
Collaborator

@watson watson commented May 15, 2018

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.

@watson
Copy link
Collaborator Author

watson commented May 15, 2018

This could maybe be improved by just calling toString() in case schema is a buffer...

@LinusU
Copy link
Collaborator

LinusU commented May 15, 2018

Very nice 👍

Unfortunately, I think that using the Buffer global will bring in the entire Buffer-polyfill when building this for the browser, could we use the is-buffer package instead?

Do you think that this should be a major or patch release? 🤔

@LinusU LinusU mentioned this pull request Aug 13, 2018
4 tasks
@LinusU LinusU added this to the 3.0.0 milestone Aug 13, 2018

tape('invalid schemas', function(t) {
t.throws(function() {
validater(Buffer.from('foo'))
Copy link
Contributor

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.

}

var compile = function(schema, cache, root, reporter, opts) {
if (Buffer.isBuffer(schema) || schema === null || (typeof schema !== 'string' && typeof schema !== 'object')) {
Copy link
Contributor

@ChALkeR ChALkeR Jul 2, 2020

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.

Copy link
Contributor

@ChALkeR ChALkeR Jul 2, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants