Add ===null to all filter params

Open Beginner friendly
#114 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
angularjs, javascript
Domain
frontend

Research direction

Look at the fuzzyBy filter in the angular-filter source code. The issue points to a specific conditional check. Find all filter parameters that use isUndefined and change them to check for null with == null. Test by setting an input to null and verifying the filter returns the collection instead of nothing.

Written by the indexing model from the issue text.

Description

Currently the (in my instance) fuzzyBy filter has this code in it

if(!isArray(collection) || isUndefined(property)
        || isUndefined(search)) {
        return collection;
      }

Search is the key word. Now say i have this value modeled to an input, when the input is blank it is set to null, but angular.isUndefined() does a typeof check on the value, not a ==undefined, or ==null.

Because of this whenever the input is blank nothing is returned by the filter. This is not the desired result is it?

This is simply fixed by changing the above to

if(!isArray(collection) || isUndefined(property)
        || search == null) {
        return collection;
      }

Because ==null will evaluate to true if search is null or undefined this should fit the bill here.

Are there any downsides to doing this everywhere?

Dominant language
JavaScript
Stars
2.9k
Forks
319
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from a8m/angular-filter

All issues in a8m/angular-filter

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.