Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/patch/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export function parsePatch(uniDiff: string): StructuredPatch[] {
bytes.push(parseInt(s.substring(j + 1, j + 4), 8));
j += 4;
}
result += new TextDecoder('utf-8').decode(new Uint8Array(bytes));
result += new TextDecoder('utf-8', {ignoreBOM: true}).decode(new Uint8Array(bytes));
continue; // j already points at the next character
}
// Note that in C, there are also three kinds of hex escape sequences:
Expand Down
9 changes: 9 additions & 0 deletions test/patch/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,15 @@ index 0000000..ce01362
}]);
});

it('should preserve a U+FEFF character in quoted filenames', function() {
for (const fileName of ['\uFEFFnote.txt', 'a\uFEFFnote.txt', 'a/\uFEFFnote.txt', 'a\uFEFF\uFEFFnote.txt']) {
const [patch] = parsePatch(createPatch(fileName, 'old\n', 'new\n'));
expect(patch.oldFileName).to.equal(fileName);
expect(patch.newFileName).to.equal(fileName);
expect(patch.index).to.equal(fileName);
}
});

it('should parse `diff --git` with unquoted filenames containing spaces (same old and new)', function() {
expect(parsePatch(
`diff --git a/file with spaces.txt b/file with spaces.txt
Expand Down