Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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

@@ -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')) {
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants