hapijs / hoek

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

contain() is always true for empty ref with only and not once #323

Closed samliebow closed 5 years ago

samliebow commented 5 years ago

Empty refs (i.e. '', [], or {}) don't have anything in the ref to not be in the values, so misses is false, so in the following block:

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

If only is true and once isn't, contain will always return true.

This bug was introduced in https://github.com/hapijs/hoek/pull/276. That's Hoek 6.0.2, and I found it via its effects on Code (expect(ref).to.only.include(value)) after version 5.2.2.

hueniverse commented 5 years ago

Thanks. Nice catch.

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.