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

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

Closed
samliebow opened this issue Aug 20, 2019 · 0 comments
Closed

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

samliebow opened this issue Aug 20, 2019 · 0 comments
Assignees
Labels
bug
Milestone

Comments

@samliebow
Copy link
Contributor

@samliebow samliebow commented Aug 20, 2019

I underdiagnosed the problem in #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:

hoek/lib/contain.js

Lines 139 to 143 in dca090d

if (options.only) {
if (misses || !options.once) {
return !misses;
}
}

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
@hueniverse hueniverse self-assigned this Sep 8, 2019
@hueniverse hueniverse added the bug label Sep 8, 2019
@hueniverse hueniverse added this to the 8.2.2 milestone Sep 8, 2019
@hueniverse hueniverse closed this in 234511d Sep 8, 2019
@hueniverse hueniverse modified the milestones: 8.2.2, 8.2.3 Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.