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

Commit e09ed5d

Browse files
author
Gonzalo Ruiz de Villa
committed
fix(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object. Closes #11782
1 parent 40e00cd commit e09ed5d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/filter/filter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
*/
128128
function filterFilter() {
129129
return function(array, expression, comparator) {
130-
if (!isArray(array)) {
130+
if (!isArrayLike(array)) {
131131
if (array == null) {
132132
return array;
133133
} else {

test/ng/filter/filterSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ describe('Filter: filter', function() {
425425
toThrowMinErr('filter', 'notarray', 'Expected array but received: {"toString":null,"valueOf":null}');
426426
});
427427

428+
it('should not throw an error if used with an array like object', function() {
429+
function ExtendedArray() {
430+
Array.call(this, arguments);
431+
}
432+
433+
ExtendedArray.prototype = Array.prototype;
434+
ExtendedArray.prototype.constructor = ExtendedArray;
435+
436+
var extendedArray = new ExtendedArray();
437+
extendedArray.push({name: 'Misko'}, {name: 'Igor'}, {name: 'Brad'});
438+
439+
expect(filter(extendedArray, 'i').length).toBe(2);
440+
});
441+
428442

429443
it('should return undefined when the array is undefined', function() {
430444
expect(filter(undefined, {})).toBeUndefined();
@@ -463,6 +477,8 @@ describe('Filter: filter', function() {
463477
});
464478

465479

480+
481+
466482
it('should match `null` against `null` only', function() {
467483
var items = [
468484
{value: null},

0 commit comments

Comments
 (0)