From a631a759d25e05d54db7c9d519cbcb48d95bdc75 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Tue, 11 Nov 2014 13:29:19 +0200 Subject: [PATCH] test(filter): test expression object with inherited properties Related to #9984 --- src/ng/filter/filter.js | 2 +- test/ng/filter/filterSpec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index a9b13068..ca010cd2 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -125,7 +125,7 @@ function filterFilter() { case 'object': // Replace `{$: 'xyz'}` with `'xyz'` and fall through var keys = Object.keys(expression); - if ((keys.length === 1) && (keys[0] === '$')) expression = expression.$; + if ((keys.length === 1) && (keys[0] === '$')) expression = expression.$; // jshint -W086 case 'boolean': case 'number': diff --git a/test/ng/filter/filterSpec.js b/test/ng/filter/filterSpec.js index dfb2ccf5..c6079cf2 100644 --- a/test/ng/filter/filterSpec.js +++ b/test/ng/filter/filterSpec.js @@ -156,6 +156,26 @@ describe('Filter: filter', function() { }); + it('should not consider the expression\'s inherited properties', function() { + Object.prototype.noop = noop; + + var items = [ + {text: 'hello'}, + {text: 'goodbye'}, + {text: 'kittens'}, + {text: 'puppies'} + ]; + + expect(filter(items, {text: 'hell'}).length).toBe(1); + expect(filter(items, {text: 'hell'})[0]).toBe(items[0]); + + expect(filter(items, 'hell').length).toBe(1); + expect(filter(items, 'hell')[0]).toBe(items[0]); + + delete(Object.prototype.noop); + }); + + describe('should support comparator', function() { it('as equality when true', function() {