fix(browser): accept HAR files that begin with a byte-order mark (#1509)
HAR 1.2 lets writers emit a UTF-8 byte-order mark and requires readers to ignore it. The decoder passed ignoreBOM: true to TextDecoder, which keeps the mark in the decoded text, so a BOM-prefixed export failed as "HAR is malformed JSON." Decoding now uses the default, which skips one leading mark. The artifact digest still covers the selected file bytes. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
911323c5dd
commit
93ca276921
@@ -1,10 +1,9 @@
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { TextDecoder } from "node:util";
|
||||
import { z } from "zod";
|
||||
import { readStableArtifact } from "../../artifacts/readStableArtifact.js";
|
||||
import { WEB_NETWORK_CAPTURE_LIMITS } from "../../domain/webNetworkCapture.js";
|
||||
import { CaptureFormatError } from "./CaptureFormatError.js";
|
||||
import { decodeHarCapture } from "./HarCapture.js";
|
||||
import { decodeHarCapture, decodeHarText } from "./HarCapture.js";
|
||||
|
||||
const requestSchema = z.strictObject({
|
||||
snapshot_path: z.string(),
|
||||
@@ -23,17 +22,12 @@ const main = async (): Promise<void> => {
|
||||
request.snapshot_path,
|
||||
WEB_NETWORK_CAPTURE_LIMITS.inputBytes,
|
||||
);
|
||||
let text: string;
|
||||
try {
|
||||
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
|
||||
snapshot.bytes,
|
||||
);
|
||||
} catch {
|
||||
throw new CaptureFormatError("format", "HAR is not valid UTF-8 JSON.");
|
||||
}
|
||||
reply = {
|
||||
ok: true,
|
||||
value: decodeHarCapture(text, request.sensitive_values),
|
||||
value: decodeHarCapture(
|
||||
decodeHarText(snapshot.bytes),
|
||||
request.sensitive_values,
|
||||
),
|
||||
};
|
||||
} catch (cause: unknown) {
|
||||
reply =
|
||||
|
||||
Reference in New Issue
Block a user