fix(numberFilter): convert all non-finite/non-numbers/non-numeric strings to the empty string

The previous code for filtering out non-finite numbers was broken, as it would convert `null` to `0`,
as well as arrays.

This change fixes this by converting null/undefined/NaN/Infinity/any object to the empty string.

Closes #6188
Closes #6261
This commit is contained in:
Sergei Z
2014-02-14 13:54:41 +02:00
committed by Caitlin Potter
parent 3018ff7130
commit cceb455fb1
2 changed files with 6 additions and 1 deletions

View File

@@ -118,7 +118,7 @@ function numberFilter($locale) {
var DECIMAL_SEP = '.';
function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
if (isNaN(number) || !isFinite(number)) return '';
if (number == null || !isFinite(number) || isObject(number)) return '';
var isNegative = number < 0;
number = Math.abs(number);

View File

@@ -128,6 +128,11 @@ describe('filters', function() {
expect(number(1234)).toEqual('1,234');
expect(number(1234.5678)).toEqual('1,234.568');
expect(number(Number.NaN)).toEqual('');
expect(number(null)).toEqual('');
expect(number({})).toEqual('');
expect(number([])).toEqual('');
expect(number(+Infinity)).toEqual('');
expect(number(-Infinity)).toEqual('');
expect(number("1234.5678")).toEqual('1,234.568');
expect(number(1/0)).toEqual("");
expect(number(1, 2)).toEqual("1.00");