fix(web): reject a negative-zero literal, which loses its sign when serialized

Copilot's twelfth pass. The suppressed comment is right and is fixed here; the
inline one is real too, but needs a core API change and is filed as #2171.

`-0` is represented exactly, so the digit comparison had nothing to say about
it — but `JSON.stringify` writes it as `0`, so the loss happens on the way
*out* rather than on the way in. The editor showed `-0` and the wire carried
`0`, and the viewer rewrote a received `-0` while pretty-printing.

`hasImpreciseIntegerLiteral` becomes `findUnsendableNumberLiteral`, checking
`Object.is(Number(literal), -0)` for every numeric spelling — `-0`, `-0.0`,
`-0e1` — before the integer-only digit check. Returning the offending literal
rather than a boolean lets the message name it, which is more use than either
of the two rules behind it and matches how the duplicate-key message reads.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UL9retfvAXRgvi6EWk4SY4
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-27 06:11:23 -04:00
commit 8aa6f01505

View file

@ -9,7 +9,7 @@
import { isSerializableJson } from "@inspector/core/json/jsonUtils.js";
import {
findDuplicateObjectKey,
hasImpreciseIntegerLiteral,
findUnsendableNumberLiteral,
} from "../../../utils/jsonObjectDraft";
/**
@ -169,7 +169,7 @@ export function formatJson(content: string): string {
function reformatsFaithfully(text: string, parsed: unknown): boolean {
return (
isSerializableJson(parsed) &&
!hasImpreciseIntegerLiteral(text) &&
findUnsendableNumberLiteral(text) === null &&
// A duplicate member name is the same class and the starkest instance:
// `{"role":"user","role":"admin"}` would be *shown* as only the second,
// which is the viewer hiding what the server sent.