diff --git a/src/patch/parse.ts b/src/patch/parse.ts index 16c1c625..e7eaf22c 100755 --- a/src/patch/parse.ts +++ b/src/patch/parse.ts @@ -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: diff --git a/test/patch/parse.js b/test/patch/parse.js index 45b9b38e..110119d8 100644 --- a/test/patch/parse.js +++ b/test/patch/parse.js @@ -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