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

fix(filterFilter): solve issue #10991 with null property value when using objects with filter #11116

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/ng/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
}

function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
var actualType = typeof actual;
var actualType = (actual !== null) ? typeof actual : 'null';
var expectedType = typeof expected;
Copy link
Member

Choose a reason for hiding this comment

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

The test made me realize that a similar "fix" is necessary for expectedType.

var expectedType = (expected !== null) ? typeof expected : 'null';


if ((expectedType === 'string') && (expected.charAt(0) === '!')) {
Expand Down
26 changes: 26 additions & 0 deletions test/ng/filter/filterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ describe('Filter: filter', function() {
});


it('should not throw an error if property is null when comparing object', function() {
var items = [
{ office:1, people: {name:'john'}},
{ office:2, people: {name:'jane'}},
{ office:3, people: null}
];
var f = { };
expect(filter(items, f).length).toBe(3);

f = { people:null };
expect(filter(items, f).length).toBe(3);
Copy link
Member

Choose a reason for hiding this comment

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

Hm...this test shouldn't pass (the length should be 1). But it does pass since version 1.3.6.
This made me realize that there is a similar bug with expectedType (see #11116 (comment)).


//should throw an error in 1.3.12
Copy link
Member

Choose a reason for hiding this comment

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

These comments are not necessary (read "should be removed" 😄).

f = { people:{ name:'john' }};
expect(filter(items, f).length).toBe(1);

//should throw an error in 1.3.12
f = { people:{ name:'j' }};
expect(filter(items, f).length).toBe(2);

//should throw an error in 1.3.12
f = { people:{ name: '' }};
expect(filter(items, f).length).toBe(2);

});

describe('should support comparator', function() {

it('not consider `object === "[object Object]"` in non-strict comparison', function() {
Expand Down