fix(diff): preserve BOM text and complete file replacements

Decode each string without consuming its leading BOM. File-type replacements emit multiple patch sections for one listed path, so retain all matching hunks. Assert the optional rename metadata in the existing commit-file journey.
This commit is contained in:
Mohamed Boudra
2026-11-06 07:24:19 +01:00
parent cee05e3c6c
commit 0a9e678286
5 changed files with 156 additions and 3 deletions
@@ -238,3 +238,33 @@ test("roundtrips generated entry lists across varint boundaries", () => {
expect(decodeDiffFrame(encodeDiffFrame(begin))).toEqual(begin);
}
});
test.each([true, false])(
"preserves BOM-prefixed paths and source lines with runs=%s",
(highlight) => {
const frame = {
opcode: 0x41 as const,
slot: 0,
revision: 1,
files: [
{
path: "\uFEFFbom.ts",
hunks: [
{
oldStart: 1,
oldCount: 1,
newStart: 1,
newCount: 1,
lines: (["add", "remove", "context"] as const).map((type) => ({
type,
content: "\uFEFFvalue",
runs: highlight ? [{ style: null, length: 6 }] : undefined,
})),
},
],
},
],
};
expect(decodeDiffFrame(encodeDiffFrame(frame))).toEqual(frame);
},
);
+1 -1
View File
@@ -93,7 +93,7 @@ export type DiffFrame = DiffBegin | DiffBodies | DiffEnd;
export class InvalidDiffFrameError extends Error {}
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder("utf-8", { fatal: true });
const textDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
class Writer {
private bytes: number[] = [];