Skip to content

Commit e41b23e

Browse files
committed
fix: guard CAST(val AS BIGINT) against Infinity from toNumber()
CAST('infinity' AS BIGINT) would call BigInt(Math.trunc(Infinity)) which throws RangeError. toNumber() can return Infinity for extreme bigint→number conversions or parseFloat("infinity"). Added Number.isFinite guard, returning 0n for non-finite values.
1 parent 06477ac commit e41b23e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/sql/evaluator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ function castValue(val: unknown, targetType: string): unknown {
219219
if (t === "bigint") {
220220
if (typeof val === "bigint") return val;
221221
if (typeof val === "string") { try { return BigInt(val); } catch { return 0n; } }
222-
return BigInt(Math.trunc(toNumber(val)));
222+
const n = toNumber(val);
223+
return Number.isFinite(n) ? BigInt(Math.trunc(n)) : 0n;
223224
}
224225
if (t === "int" || t === "integer") return Math.trunc(toNumber(val));
225226
if (t === "float" || t === "double" || t === "real" || t === "decimal" || t === "numeric") return toNumber(val);

0 commit comments

Comments
 (0)