Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(filterFilter): Fix filtering using an object expression when the filter value is undefined #10427

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ng/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
comparator = equals;
} else if (!isFunction(comparator)) {
comparator = function(actual, expected) {
if (isUndefined(expected)) {
return true;
}

if (isObject(actual) || isObject(expected)) {
// Prevent an object to be considered equal to a string like `'[object'`
return false;
Expand Down
12 changes: 12 additions & 0 deletions test/ng/filter/filterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ describe('Filter: filter', function() {
});


it('should filter when property is undefined', function() {
var items = [{name: 'a'}, {name: 'abc'}];
expect(filter(items, {name: undefined})).toEqual([{name: 'a'}, {name: 'abc'}]);
});


it('should filter when a deep property is undefined', function() {
var items = [{name: 'a'}, {name: 'abc'}, {deep: {name: 'abc'}}];
expect(filter(items, {deep: {name: undefined}})).toEqual([{deep: {name: 'abc'}}]);
});


it('should take function as predicate', function() {
var items = [{name: 'a'}, {name: 'abc', done: true}];
expect(filter(items, function(i) {return i.done;}).length).toBe(1);
Expand Down