From 9613938fc9cab75483f597ed05f4f4466244bf6b Mon Sep 17 00:00:00 2001 From: Dav Date: Thu, 19 Feb 2015 15:25:46 +0100 Subject: [PATCH 1/6] fix(filterFilter): test for pull request fix(filterFilter): solve issue #10991 with null property value when using objects with filter : test --- test/ng/filter/filterSpec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/ng/filter/filterSpec.js b/test/ng/filter/filterSpec.js index 0318ae57bcf6..df4db7a56fdf 100644 --- a/test/ng/filter/filterSpec.js +++ b/test/ng/filter/filterSpec.js @@ -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); + + //should throw an error in 1.3.12 + 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() { From 541a948b67dd39dad1cfc1be5593f67f1ca5692f Mon Sep 17 00:00:00 2001 From: Dav Date: Thu, 19 Feb 2015 17:09:59 +0100 Subject: [PATCH 2/6] fix(filterFilter): solve issue #10991 with null property value when using objects with filter fix(filterFilter): solve issue #10991 with null property value when using objects with filter Regarding the issue #10991 and the following discussion #10992 --- src/ng/filter/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index 0ec98fc27099..4f45e1aeaf5a 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -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; if ((expectedType === 'string') && (expected.charAt(0) === '!')) { From 603a9db11212753b303bc1ce07d952e1a4ebbe86 Mon Sep 17 00:00:00 2001 From: Dav Date: Thu, 19 Feb 2015 18:07:05 +0100 Subject: [PATCH 3/6] removing trailing white space from previous fix --- src/ng/filter/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index 4f45e1aeaf5a..e84b8823e830 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -187,7 +187,7 @@ function createPredicateFn(expression, comparator, matchAgainstAnyProp) { } function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) { - var actualType = (actual !== null) ? typeof actual : 'null'; + var actualType = (actual !== null) ? typeof actual : 'null'; var expectedType = typeof expected; if ((expectedType === 'string') && (expected.charAt(0) === '!')) { From d8c81f8591f7723306787e4d559fbb34111b09e5 Mon Sep 17 00:00:00 2001 From: Dav Date: Thu, 19 Feb 2015 18:09:59 +0100 Subject: [PATCH 4/6] removing trailing whitespace --- test/ng/filter/filterSpec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/ng/filter/filterSpec.js b/test/ng/filter/filterSpec.js index df4db7a56fdf..7c4b546be89e 100644 --- a/test/ng/filter/filterSpec.js +++ b/test/ng/filter/filterSpec.js @@ -428,7 +428,7 @@ describe('Filter: filter', function() { }); - it ('should not throw an error if property is null when comparing object', 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'}}, @@ -436,22 +436,22 @@ describe('Filter: filter', function() { ]; var f = { }; expect(filter(items, f).length).toBe(3); - + f = { people:null }; expect(filter(items, f).length).toBe(3); - + //should throw an error in 1.3.12 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() { From 3a7af5c0a7f065a214a0ec5155f8c645d21649df Mon Sep 17 00:00:00 2001 From: Dav Date: Wed, 25 Feb 2015 13:02:28 +0100 Subject: [PATCH 5/6] fix(filterFilter) : issue when expectedVal is null see #11116 discussion --- src/ng/filter/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index e84b8823e830..624253a2e73a 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -188,7 +188,7 @@ function createPredicateFn(expression, comparator, matchAgainstAnyProp) { function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) { var actualType = (actual !== null) ? typeof actual : 'null'; - var expectedType = typeof expected; + var expectedType = (expected !== null) ? typeof expected : 'null'; if ((expectedType === 'string') && (expected.charAt(0) === '!')) { return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp); From 817d19d0a1c333104c7ef9164ed0eb38c2281327 Mon Sep 17 00:00:00 2001 From: Dav Date: Wed, 25 Feb 2015 13:08:06 +0100 Subject: [PATCH 6/6] fix(filterFilter) : test case for "issue when expectedVal is null" add test case for new fix --- test/ng/filter/filterSpec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/ng/filter/filterSpec.js b/test/ng/filter/filterSpec.js index 7c4b546be89e..97cfae8444ca 100644 --- a/test/ng/filter/filterSpec.js +++ b/test/ng/filter/filterSpec.js @@ -438,20 +438,20 @@ describe('Filter: filter', function() { expect(filter(items, f).length).toBe(3); f = { people:null }; - expect(filter(items, f).length).toBe(3); - - //should throw an error in 1.3.12 - f = { people:{ name:'john' }}; expect(filter(items, f).length).toBe(1); - //should throw an error in 1.3.12 - f = { people:{ name:'j' }}; + f = { people: {}}; 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); + f = { people:{ name:'john' }}; + expect(filter(items, f).length).toBe(1); + + f = { people:{ name:'j' }}; + expect(filter(items, f).length).toBe(2); + }); describe('should support comparator', function() {