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

Commit

Permalink
fix(numberFilter): convert all non-finite/non-numbers/non-numeric str…
Browse files Browse the repository at this point in the history
…ings 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
  • Loading branch information
sagens42 authored and caitp committed Feb 15, 2014
1 parent 3018ff7 commit cceb455
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit cceb455

Please sign in to comment.