Skip to content

Commit 92cabf7

Browse files
committed
fix: guard BigInt(float) crash in SQL multi-column ORDER BY comparator
BigInt(3.14) throws — use Math.trunc before conversion, matching the pattern already used in decode.ts and evaluator.ts.
1 parent 632cfc5 commit 92cabf7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/sql/executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export class SqlWrappingExecutor implements QueryExecutor {
134134
let cmp: number;
135135
if (typeof av === "number" && typeof bv === "number") cmp = av - bv;
136136
else if (typeof av === "bigint" && typeof bv === "bigint") cmp = av < bv ? -1 : av > bv ? 1 : 0;
137-
else if (typeof av === "bigint" && typeof bv === "number") cmp = av < BigInt(bv) ? -1 : av > BigInt(bv) ? 1 : 0;
138-
else if (typeof av === "number" && typeof bv === "bigint") cmp = BigInt(av) < bv ? -1 : BigInt(av) > bv ? 1 : 0;
137+
else if (typeof av === "bigint" && typeof bv === "number") { const bb = BigInt(Math.trunc(bv)); cmp = av < bb ? -1 : av > bb ? 1 : 0; }
138+
else if (typeof av === "number" && typeof bv === "bigint") { const ab = BigInt(Math.trunc(av)); cmp = ab < bv ? -1 : ab > bv ? 1 : 0; }
139139
else cmp = String(av).localeCompare(String(bv));
140140
if (cmp !== 0) return direction === "desc" ? -cmp : cmp;
141141
}

0 commit comments

Comments
 (0)