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

"in" expression always returns false if needle argument is null #9465

Closed
lbutler opened this issue Mar 25, 2020 · 1 comment · Fixed by #9450
Closed

"in" expression always returns false if needle argument is null #9465

lbutler opened this issue Mar 25, 2020 · 1 comment · Fixed by #9450
Labels
bug 🐞 needs investigation 🔍 Issues that require further research (e.g. it's not clear whether it's GL JS or something else)

Comments

@lbutler
Copy link
Contributor

lbutler commented Mar 25, 2020

mapbox-gl-js version: 1.9.0

Steps to Trigger Behavior

  1. Use an in expression that has the needle as null with the haystack as an array containing null - e.g. `['in', null, ["literal", [1,2,3,null,5] ]]
  2. The expression will always return false

Link to Demonstration

https://jsbin.com/qepihirize/edit?js,output

Each circle is a needle of a different type, they should all be black as they are within the haystack.

Expected Behavior

Be able to find null within an array

Actual Behavior

in will always return false


When implementing the index-of expression (#9443) I noticed that in will always return false if the needle is null even if the haystack is an array of values that contains a null.

The line that is causing this issue is below, it appears that it was changed in #9295 to allow false but still filters out null and undefined and shortcuts to return false.

if (needle == null || !haystack) return false;

I'd expect index-of and in to work the same way, just so we don't get conflicting answers for the below edge case:

['in', null, ["literal", [1,2,3,null,5] ]]                     // false
["==", ['index-of', null, ["literal", [1,2,3,null,5] ]], -1]   // true

I can fix this as part of my PR #9450 but just wanted to confirm that this wasn't another reason why we have this behaviour.

@mourner mourner added bug 🐞 needs investigation 🔍 Issues that require further research (e.g. it's not clear whether it's GL JS or something else) labels Mar 26, 2020
@lbutler
Copy link
Contributor Author

lbutler commented Mar 26, 2020

@ryanhamley provided some extra information about this bug as part of the review of the slice/index-of expression PR #9450 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 needs investigation 🔍 Issues that require further research (e.g. it's not clear whether it's GL JS or something else)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants