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

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 #6771
Closes #7118
  • Loading branch information
caitp committed Apr 15, 2014
1 parent b10a437 commit 5dee9e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ng/filter/limitTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ 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);
});
});

1 comment on commit 5dee9e4

@caitp
Copy link
Contributor Author

@caitp caitp commented on 5dee9e4 Apr 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit should actually reference #6772, not #7118 (I just had too many tabs open when amending the commit, and got the wrong issue number) :(

Please sign in to comment.