Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect.each([
{ scenario: "kept", before: "\uFEFFold\n", after: "\uFEFFnew\n" },
{ scenario: "added", before: "same\n", after: "\uFEFFsame\n" },
{ scenario: "removed", before: "\uFEFFsame\n", after: "same\n" },
])("preserves byte-order marks in diff expansion when $scenario", ({ before, after }) =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
yield* initRepoWithCommit(cwd);
yield* writeTextFile(cwd, "README.md", before);
yield* git(cwd, ["commit", "-am", "write original contents"]);
yield* writeTextFile(cwd, "README.md", after);
const driver = yield* GitVcsDriver.GitVcsDriver;

const contents = yield* driver.getReviewDiffFileContents(
makeReviewDiffFileContentsInput(cwd),
);

assert.deepStrictEqual(contents, { oldContents: before, newContents: after });
}),
);

it.effect("reads a base ref that looks like an option as a revision", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ const collectOutput = Effect.fnUntraced(function* (
onLine: ((line: string) => Effect.Effect<void, never>) | undefined,
keepLineCallbacksAfterTruncation = false,
): Effect.fn.Return<{ readonly text: string; readonly truncated: boolean }, GitCommandError> {
const decoder = new TextDecoder();
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
const lineDecoder = keepLineCallbacksAfterTruncation && onLine ? new TextDecoder() : null;
let bytes = 0;
let text = "";
Expand Down Expand Up @@ -3326,7 +3326,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
if (bytes.includes(0)) {
return yield* fileError("fs.readFile", `Cannot expand binary file '${input.newPath}'.`);
}
return new TextDecoder("utf-8").decode(bytes);
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
});

const getReviewDiffFileContents = Effect.fn("getReviewDiffFileContents")(function* (
Expand Down
Loading