From 36d1d6a42c18b4c7743c24ff3ebf02e81c470f7b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 6 Feb 2017 11:48:52 +0100 Subject: [PATCH] =?utf8?q?kivi.parse=5Famount:=20bei=20ung=C3=BCltigen=20m?= =?utf8?q?athematischen=20Ausdr=C3=BCcken=200=20zur=C3=BCckliefern?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Ansonsten würde eine Exception geworfen, was ein anderes Verhalten als bei der Perl-Variante wäre. --- js/kivi.js | 6 +++++- js/t/kivi/parse_amount.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/js/kivi.js b/js/kivi.js index dbf5a0ed2..c6b707473 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -66,7 +66,11 @@ namespace("kivi", function(ns) { return 0; /* jshint -W061 */ - return eval(amount); + try { + return eval(amount); + } catch (err) { + return 0; + } }; ns.round_amount = function(amount, places) { diff --git a/js/t/kivi/parse_amount.js b/js/t/kivi/parse_amount.js index 1ef2b1193..1c267c440 100644 --- a/js/t/kivi/parse_amount.js +++ b/js/t/kivi/parse_amount.js @@ -115,3 +115,9 @@ QUnit.test("kivi.parse_amount function German number style with thousand separat assert.equal(kivi.parse_amount('iuh !@#$% 10,00'), 0, 'iuh !@#$% 10,00'); }); + +QUnit.test("kivi.parse_amount function German number style with thousand separator & invalid math expression", function( assert ) { + kivi.setup_formats({ numbers: '1.000,00' }); + + assert.equal(kivi.parse_amount('54--42'), 0, '54--42'); +}); -- 2.20.1