mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-05 22:35:14 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user