mafintosh / is-my-json-valid

A JSONSchema validator that uses code generation to be extremely fast
MIT License
965 stars 111 forks source link

Non-greedy (default) mode is broken (returning true on invalid) on mixed type rules #179

Closed ChALkeR closed 4 years ago

ChALkeR commented 4 years ago

Due to https://github.com/mafintosh/is-my-json-valid/blob/b5f46cd3c04c78fa15212ebfe95054b98c447bfb/index.js#L234-L241

If type is not an object, missing is undefined, which is not strict equal to 0, and all follow-up checks (including ones intended for non-objects) are excluded.

Testcase:

const tape = require('tape')
const validator = require('is-my-json-valid')

tape('test', (t) => {
  const validate = validator({ required: [], uniqueItems: true })
  t.notOk(validate([1, 1]), 'required + uniqueItems')
  t.end()
})