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

Commit 01161a0

Browse files
ElephantRosepetebacondarwin
authored andcommittedFeb 27, 2015
fix(filterFilter): do not throw an error if property is null when comparing objects
Closes #10991 Closes #10992 Closes #11116
1 parent 75abbd5 commit 01161a0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
 

‎src/ng/filter/filter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
181181
}
182182

183183
function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
184-
var actualType = typeof actual;
185-
var expectedType = typeof expected;
184+
var actualType = (actual !== null) ? typeof actual : 'null';
185+
var expectedType = (expected !== null) ? typeof expected : 'null';
186186

187187
if ((expectedType === 'string') && (expected.charAt(0) === '!')) {
188188
return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp);

‎test/ng/filter/filterSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,33 @@ describe('Filter: filter', function() {
399399
});
400400

401401

402+
it('should not throw an error if property is null when comparing object', function() {
403+
var items = [
404+
{ office:1, people: {name:'john'}},
405+
{ office:2, people: {name:'jane'}},
406+
{ office:3, people: null}
407+
];
408+
var f = { };
409+
expect(filter(items, f).length).toBe(3);
410+
411+
f = { people:null };
412+
expect(filter(items, f).length).toBe(1);
413+
414+
f = { people: {}};
415+
expect(filter(items, f).length).toBe(2);
416+
417+
f = { people:{ name: '' }};
418+
expect(filter(items, f).length).toBe(2);
419+
420+
f = { people:{ name:'john' }};
421+
expect(filter(items, f).length).toBe(1);
422+
423+
f = { people:{ name:'j' }};
424+
expect(filter(items, f).length).toBe(2);
425+
426+
});
427+
428+
402429
describe('should support comparator', function() {
403430

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

0 commit comments

Comments
 (0)
This repository has been archived.