Skip to content

Commit

Permalink
Better input validation
Browse files Browse the repository at this point in the history
Fix #261
  • Loading branch information
BenjaminVanRyseghem committed Mar 27, 2017
1 parent 6c0595e commit 02ce326
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion numbro.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,10 @@
input = input.value();
} else if (input === 0 || typeof input === 'undefined') {
input = 0;
} else if (!Number(input)) {
} else if (typeof input === 'string' || typeof input === 'number') {
input = numbro.fn.unformat(input);
} else {
throw new Error('Invalid input');
}

return new Numbro(Number(input));
Expand Down
12 changes: 12 additions & 0 deletions tests/numbro/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,18 @@ exports.format = {
}

test.done();
},

regression261: function(test) {
// Setup
var currentCulture = numbro.culture();

numbro.culture("de-DE");
var result = numbro("100.000").format();
test.strictEqual(result, "100.000");

//Teardown
numbro.culture(currentCulture);
test.done();
}
};

0 comments on commit 02ce326

Please sign in to comment.