fix(json): name a leading byte-order mark in rejected JSON input (#1510)
Strict JSON file inputs reject a leading UTF-8 byte-order mark, but the
diagnostic was the parser's own message, which quotes the invisible U+FEFF
as the unexpected token: Unexpected token '', "{"invento"... is not
valid JSON. Editors such as Windows PowerShell 5.1 write that mark by
default, and nothing in the message showed it.
CLI JSON files (whole and streamed), Evidence and snapshot JSON files, and
process scenario files now report that the input begins with a UTF-8
byte-order mark and how to save it. Acceptance is unchanged.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
93ca276921
commit
a936303723
@@ -9,6 +9,7 @@ import { createCli } from "../../../src/cli.js";
|
||||
import { parseCliJsonInput } from "../../../src/cliJsonInput.js";
|
||||
import { readCliJsonFile } from "../../../src/cliJsonFile.js";
|
||||
import { analysisCliErrorEnvelopeSchema } from "../../../src/contracts/errorSchemas.js";
|
||||
import { JSON_BYTE_ORDER_MARK_MESSAGE } from "../../../src/application/Utf8JsonInput.js";
|
||||
import { readWithoutFifoWriter } from "../../fixtures/fifoInput.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -160,6 +161,21 @@ describe("CLI JSON streamed input", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("names a leading byte-order mark in small and streamed files", async () => {
|
||||
const root = await createTestTempDirectory("rea-json-input-bom-");
|
||||
const path = join(root, "input.json");
|
||||
for (const body of ["{}", `${" ".repeat(9 * 1024 * 1024)}{}`]) {
|
||||
await writeFile(path, `\uFEFF${body}`);
|
||||
expect(await parseCliJsonInput(path, "test-input")).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
input_reason: "invalid-json",
|
||||
details: { issues: [{ message: JSON_BYTE_ORDER_MARK_MESSAGE }] },
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it.each([Buffer.from([0xf0, 0x28, 0x8c, 0xbc]), Buffer.from([0xe2, 0x82])])(
|
||||
"rejects malformed and incomplete UTF-8 at a read boundary (%j)",
|
||||
async (invalid) => {
|
||||
|
||||
Reference in New Issue
Block a user