Skip to content

Commit

Permalink
fix(limitTo): do not convert Infinity to NaN
Browse files Browse the repository at this point in the history
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 angular#6771
  • Loading branch information
caitp committed Mar 21, 2014
1 parent 6011145 commit 5232461
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ng/filter/limitTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ function limitToFilter(){
return function(input, limit) {
if (!isArray(input) && !isString(input)) return input;

limit = int(limit);
if (Math.abs(Number(limit)) === Infinity) limit = Number(limit);
else limit = int(limit);

if (isString(input)) {
//NaN check on limit
Expand Down
14 changes: 14 additions & 0 deletions test/ng/filter/limitToSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@ describe('Filter: limitTo', function() {
expect(limitTo(str, -9)).toEqual(str);
expect(limitTo(str, '-9')).toEqual(str);
})

it('should return entire input array when limited by Infinity', function() {
expect(limitTo(items, Infinity)).toEqual(items);
expect(limitTo(items, 'Infinity')).toEqual(items);
expect(limitTo(items, -Infinity)).toEqual(items);
expect(limitTo(items, '-Infinity')).toEqual(items);
});

it('should return the entire string when limited by Infinity', function() {
expect(limitTo(str, Infinity)).toEqual(str);
expect(limitTo(str, 'Infinity')).toEqual(str);
expect(limitTo(str, -Infinity)).toEqual(str);
expect(limitTo(str, '-Infinity')).toEqual(str);
});
});

0 comments on commit 5232461

Please sign in to comment.