fix: implies should not fail when implied key's value is 0, false or empty string #1985
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attemps at fixing #1091 and #1203.
The issue
The documentation for
implies
is:But this check fails when the value of the key
y
is0
,false
, or empty string.When
y
value isfalse
, we might wantimplies
to continue failing though. I'd like to have your input on that, and I will adjust that PR accordingly.The issue came from
keyExists
which, instead of always returning a boolean, could returned the value of the key. That value is later on used like so:Thus, that
if
resolved totrue
whenvalue
was0
,false
or""
.The fix
Having
keyExists
always returning a boolean seems more robust. I usedObject.hasOwnProperty
to check for presence of the key instead.Let me know if you think that
keyExists
should still returnfalse
when the value of the key isfalse
.Thanks :)