mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
* Fix logic for empty or invalid values
This commit is contained in:
parent
3239d5599f
commit
7f260ec86b
1 changed files with 2 additions and 4 deletions
|
@ -32,13 +32,11 @@ class BasicArithmetic extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
if (parseInt(input, 10).toString().length === input.length) {
|
||||
const val = parseInt(input, 10);
|
||||
return val;
|
||||
return parseInt(input, 10);
|
||||
} else if (input.match(/[+-]?([0-9.]+)/g)) {
|
||||
return (input.replace(/\s/g, "").match(/[+-]?([0-9.]+)/g) || [])
|
||||
.reduce(function (sum, value) {
|
||||
const val = parseFloat(sum) + parseFloat(value);
|
||||
return val;
|
||||
return parseFloat(sum) + parseFloat(value);
|
||||
});
|
||||
} else {
|
||||
return NaN;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue