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
8 changes: 8 additions & 0 deletions packages/shared/src/gitPatchPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("a name written into a header and read back out", () => {
"with space.txt",
"café/résumé.ts",
"🚀.ts",
"\uFEFFtab\tfile.txt",
"tab\tfile.txt",
"line\nfile.txt",
"carriage\rfile.txt",
Expand Down Expand Up @@ -66,6 +67,13 @@ describe("a name written into a header and read back out", () => {
});

describe("unquoteGitPatchPath", () => {
it.each(['"\\357\\273\\277note.txt"', "\\357\\273\\277note.txt"])(
"preserves an escaped U+FEFF at the start of a filename: %j",
(token) => {
expect(unquoteGitPatchPath(token)).toBe("\uFEFFnote.txt");
},
);

it("leaves a token git saw no need to quote alone", () => {
expect(unquoteGitPatchPath("src/app.ts")).toBe("src/app.ts");
expect(unquoteGitPatchPath("with space.txt")).toBe("with space.txt");
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/gitPatchPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const LOWEST_PRINTABLE = 0x20;
const BACKSLASH = 0x5c;

const utf8 = new TextEncoder();
const fromUtf8 = new TextDecoder();
// A leading U+FEFF is part of the filename, not an encoding marker.
const fromUtf8 = new TextDecoder("utf-8", { ignoreBOM: true });

/**
* A name as a patch header can carry it: itself where that is unambiguous, and git's quoted form
Expand Down
14 changes: 14 additions & 0 deletions packages/source-control-core/src/server/diffFileRevisions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ describe("parseDiffFileRevisions", () => {
assert.deepStrictEqual([...revisions], [["new.ts", "2222222"]]);
});

it("keeps a leading U+FEFF in a quoted rename's revision key", () => {
const revisions = parseDiffFileRevisions(
patchOf(
'diff --git a/old.txt "b/\\357\\273\\277note.txt"',
"similarity index 100%",
"rename from old.txt",
'rename to "\\357\\273\\277note.txt"',
"index 2222222..2222222 100644",
),
);

assert.deepStrictEqual([...revisions], [["\uFEFFnote.txt", "2222222"]]);
});

it("leaves out a file Bitbucket excluded, which it gives no index line for", () => {
const revisions = parseDiffFileRevisions(
patchOf(
Expand Down
Loading