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
This commit is contained in:
Caitlin Potter
2014-03-20 11:13:05 -04:00
parent 373078a94c
commit fcdac65aed
2 changed files with 19 additions and 1 deletions

View File

@@ -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

View File

@@ -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);
});
});