mirror of
https://github.com/gchq/CyberChef.git
synced 2026-03-26 16:51:26 -07:00
add function to enforce base 10 decimal sytnax before parsing
This commit is contained in:
parent
e95782eba7
commit
fd1be923b2
1 changed files with 8 additions and 0 deletions
|
|
@ -36,6 +36,12 @@ function safeBigInt(str, context="number") {
|
|||
}
|
||||
}
|
||||
|
||||
function validateDecimal(input) {
|
||||
// validates optional-sign base-10 decimal input: integers, decimals with optional digits before or after the decimal point, and scientific notation
|
||||
if (!/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i.test(input))
|
||||
throw new Error("Invalid decimal number");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute 10^exp as BigInt without using ** on BigInt, to avoid
|
||||
|
|
@ -212,6 +218,8 @@ export function ToIEEE754Float64(input) {
|
|||
return `${s} ${expOnes} ${mantZeros}`;
|
||||
}
|
||||
|
||||
validateDecimal(input);
|
||||
|
||||
let sign = 0n;
|
||||
if (input.startsWith("-")) {
|
||||
sign = 1n;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue