Skip to content

Commit a7c75d0

Browse files
committed
test(filter): test expression object with inherited properties
Related to angular#9984
1 parent a842315 commit a7c75d0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ng/filter/filter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function filterFilter() {
125125
case 'object':
126126
// Replace `{$: 'xyz'}` with `'xyz'` and fall through
127127
var keys = Object.keys(expression);
128-
if ((keys.length === 1) && (keys[0] === '$')) expression = expression.$;
128+
if ((keys.length === 1) && (keys[0] === '$')) expression = expression.$;
129129
// jshint -W086
130130
case 'boolean':
131131
case 'number':

test/ng/filter/filterSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ describe('Filter: filter', function() {
156156
});
157157

158158

159+
it('should not consider the expression\'s inherited properties', function() {
160+
Object.prototype.noop = noop;
161+
162+
var items = [
163+
{text: 'hello'},
164+
{text: 'goodbye'},
165+
{text: 'kittens'},
166+
{text: 'puppies'}
167+
];
168+
169+
expect(filter(items, {text: 'hell'}).length).toBe(1);
170+
expect(filter(items, {text: 'hell'})[0]).toBe(items[0]);
171+
172+
expect(filter(items, 'hell').length).toBe(1);
173+
expect(filter(items, 'hell')[0]).toBe(items[0]);
174+
175+
delete(Object.prototype.noop);
176+
});
177+
178+
159179
describe('should support comparator', function() {
160180

161181
it('as equality when true', function() {

0 commit comments

Comments
 (0)