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

Commit fcdac65

Browse files
committed
fix(limitTo): do not convert Infinity to NaN
parseInt(Infinity, 10) will result in NaN, which becomes undesirable when the expected behaviour is to return the entire input. I believe this is possibly useful as a way to toggle input limiting based on certain factors. Closes #6771 Closes #7118
1 parent 373078a commit fcdac65

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ng/filter/limitTo.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ function limitToFilter(){
7373
return function(input, limit) {
7474
if (!isArray(input) && !isString(input)) return input;
7575

76-
limit = int(limit);
76+
if (Math.abs(Number(limit)) === Infinity) {
77+
limit = Number(limit);
78+
} else {
79+
limit = int(limit);
80+
}
7781

7882
if (isString(input)) {
7983
//NaN check on limit

test/ng/filter/limitToSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,18 @@ describe('Filter: limitTo', function() {
6868
expect(limitTo(str, -9)).toEqual(str);
6969
expect(limitTo(str, '-9')).toEqual(str);
7070
})
71+
72+
it('should return entire input array when limited by Infinity', function() {
73+
expect(limitTo(items, Infinity)).toEqual(items);
74+
expect(limitTo(items, 'Infinity')).toEqual(items);
75+
expect(limitTo(items, -Infinity)).toEqual(items);
76+
expect(limitTo(items, '-Infinity')).toEqual(items);
77+
});
78+
79+
it('should return the entire string when limited by Infinity', function() {
80+
expect(limitTo(str, Infinity)).toEqual(str);
81+
expect(limitTo(str, 'Infinity')).toEqual(str);
82+
expect(limitTo(str, -Infinity)).toEqual(str);
83+
expect(limitTo(str, '-Infinity')).toEqual(str);
84+
});
7185
});

0 commit comments

Comments
 (0)