fix(query): serialize 64-bit integers beyond js safe range as strings

Closes #7832
This commit is contained in:
t8y2 committed 2026-09-06 13:01:37 +08:00
1 parent c0b4fa09cc
commit 5acc5f7e82
4 files changed
+270 -3

No files matched your search

+15 -1
View File
@@ -1,5 +1,19 @@
import { describe, expect, it } from "vitest";
import { firstLineCellDisplayValue } from "@/lib/dataGrid/cellValue";
import { displayCellValue, firstLineCellDisplayValue } from "@/lib/dataGrid/cellValue";
describe("displayCellValue", () => {
it("renders 64-bit integer strings beyond the JS safe range verbatim (issue #7832)", () => {
// The Rust backend ships BIGINT cells above ±(2^53 - 1) as decimal
// strings; the grid must keep every digit instead of routing them
// through Number(), which zeroes the trailing digits.
expect(displayCellValue("1391198305898897409")).toBe("1391198305898897409");
expect(displayCellValue("18446744073709551615")).toBe("18446744073709551615");
expect(displayCellValue("-9007199254740992")).toBe("-9007199254740992");
// Safe-range integers keep crossing as JSON numbers.
expect(displayCellValue(9007199254740991)).toBe("9007199254740991");
expect(displayCellValue(42)).toBe("42");
});
});
describe("firstLineCellDisplayValue", () => {
it("shows only the first line in fixed-height cells", () => {
@@ -59,6 +59,21 @@ describe("simpleDataGridOrderByMatchesSort", () => {
});
});
describe("compareDataGridValues numeric ordering", () => {
it("sorts bigint string cells beyond the JS safe range numerically (issue #7832)", () => {
// BIGINT cells above ±(2^53 - 1) cross the backend boundary as decimal
// strings, like DECIMAL cells; numeric columns must still order them by
// magnitude instead of falling back to collation or double rounding.
const columnType = "bigint";
expect(compareDataGridValues("1391198305898897409", "1391198305898909792", columnType)).toBeLessThan(0);
expect(compareDataGridValues("1391198305898909792", "1391198305898897409", columnType)).toBeGreaterThan(0);
expect(compareDataGridValues("9007199254740993", "1391198305898897409", columnType)).toBeLessThan(0);
expect(compareDataGridValues(42, "9007199254740993", columnType)).toBeLessThan(0);
expect(compareDataGridValues("-9007199254740992", "42", columnType)).toBeLessThan(0);
expect(compareDataGridValues("1391198305898897409", "1391198305898897409", columnType)).toBe(0);
});
});
describe("compareDataGridValues datetime ordering", () => {
it("orders space-separated timestamps with microsecond precision", () => {
expect(compareDataGridValues("2024-01-01 12:00:00.123456", "2024-01-01 12:00:00.500000")).toBeLessThan(0);