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
1b9f0cda98
commit
3239d5599f
1 changed files with 10 additions and 13 deletions
|
@ -4,7 +4,6 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
|
@ -32,19 +31,17 @@ class BasicArithmetic extends Operation {
|
|||
* @returns {number}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (input.length >= 1) {
|
||||
if (parseInt(input, 10).toString().length === input.length) {
|
||||
const val = parseInt(input, 10);
|
||||
return BigNumber.isBigNumber(val) ? val : new BigNumber(NaN);
|
||||
} else {
|
||||
return val;
|
||||
} 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 BigNumber.isBigNumber(val) ? val : new BigNumber(NaN);
|
||||
return val;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return new BigNumber(NaN);
|
||||
return NaN;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue