Skip to content

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

@lbutler

Description

@lbutler

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞needs investigation 🔍Issues that require further research (e.g. it's not clear whether it's GL JS or something else)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions