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,4 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { TextDecoder } from "node:util";
|
||||
import { isSafeNumber, LosslessNumber } from "lossless-json";
|
||||
import { parseHarJson } from "./HarJson.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
@@ -25,6 +26,19 @@ type Projection = Pick<
|
||||
"reported" | "numeric_literals" | "binary_fields" | "redactions"
|
||||
>;
|
||||
|
||||
/**
|
||||
* Decode retained HAR bytes as UTF-8. HAR 1.2 lets writers emit a byte-order
|
||||
* mark and requires readers to ignore it, so one leading BOM is skipped.
|
||||
*/
|
||||
export const decodeHarText = (bytes: Uint8Array): string => {
|
||||
try {
|
||||
// ignoreBOM: false (the default) is what skips the mark; true keeps it.
|
||||
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
||||
} catch {
|
||||
throw new CaptureFormatError("format", "HAR is not valid UTF-8 JSON.");
|
||||
}
|
||||
};
|
||||
|
||||
/** Decode a retained HAR with exact numeric lexemes and unchanged upstream schema validation. */
|
||||
export const decodeHarCapture = (
|
||||
text: string,
|
||||
|
||||
Reference in New Issue
Block a user