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

Allow the second argument to 'in' expression to be an empty string #11547

Merged
merged 1 commit into from
Mar 7, 2022

Conversation

ryanhamley
Copy link
Contributor

@ryanhamley ryanhamley commented Feb 23, 2022

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Allow the second argument to the 'in' expression operator to be an empty string</changelog>

@ryanhamley ryanhamley self-assigned this Feb 23, 2022
@@ -42,7 +42,7 @@ class In implements Expression {
const needle = (this.needle.evaluate(ctx): any);
const haystack = (this.haystack.evaluate(ctx): any);

if (!haystack) return false;
if (haystack == null) return false;
Copy link
Contributor

@avpeery avpeery Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be triple equals? Will == null on an empty string ever evaluate as true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a way of detecting undefined and null values while allowing other falsey values to pass through.

undefined == null // true
null == null // true
false == null // false
'' == null // false

@ryanhamley ryanhamley merged commit 531e435 into main Mar 7, 2022
@ryanhamley ryanhamley deleted the in-allow-empty-string branch March 7, 2022 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

["in", "", <empty string>] returns false
2 participants