hapijs / hoek

Node utilities shared among the extended hapi universe
Other
480 stars 171 forks source link

contain() passes with extra values with only and not once #327

Closed samliebow closed 5 years ago

samliebow commented 5 years ago

I underdiagnosed the problem in https://github.com/hapijs/hoek/issues/323: a reference doesn't have to be empty for the only flag to allow values that aren't in the ref. The underlying issue appears to be the same: there's nothing in the ref that isn't in the values, so there's no misses, so this block returns true: https://github.com/hapijs/hoek/blob/dca090d1da8515b48c235afbba0ca187f4b3c476/lib/contain.js#L139-L143

Examples:

contain(['a', 'b'], ['a', 'b', 'c']) // false
contain(['a', 'b'], ['a', 'b', 'c'], { only: true }) // true
contain(['a', 'b'], ['a', 'b', 'c'], { only: true, once: true }) // false

contain('ab', ['a', 'b', 'c']) // false
contain('ab', ['a', 'b', 'c'], { only: true }) // true
contain('ab', ['a', 'b', 'c'], { only: true, once: true }) // false

contain({ a: 'foo', b: 'bar' }, ['a', 'b', 'c']) // false
contain({ a: 'foo', b: 'bar' }, ['a', 'b', 'c'], { only: true }) // true
contain({ a: 'foo', b: 'bar' }, ['a', 'b', 'c'], { only: true, once: true }) // false
lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.