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
16 changes: 16 additions & 0 deletions src/__tests__/diff-parser-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ describe('DiffParser', () => {
`);
});

it('should parse diff with a space in the file name', () => {
// git ends --- and +++ names that contain a space with a TAB
const diff =
'diff --git a/My Docs/app.js b/My Docs/app.js\n' +
'index 4c679d7..e9bd385 100644\n' +
'--- a/My Docs/app.js\t\n' +
'+++ b/My Docs/app.js\t\n' +
'@@ -1 +1,2 @@\n' +
' const x = 1;\n' +
'+const y = 2;';
const [file] = parse(diff);
expect(file.oldName).toBe('My Docs/app.js');
expect(file.newName).toBe('My Docs/app.js');
expect(file.language).toBe('js');
});

it('should parse diff with prefix', () => {
const diff =
'diff --git "\tbla with \ttab.scala" "\tbla with \ttab.scala"\n' +
Expand Down
4 changes: 3 additions & 1 deletion src/diff-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function getFilename(line: string, linePrefix?: string, extraPrefix?: string): s

const [, filename = ''] = FilenameRegExp.exec(line) || [];
const matchingPrefix = prefixes.find(p => filename.indexOf(p) === 0);
const fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename;
const fnameWithoutPrefix = (matchingPrefix ? filename.slice(matchingPrefix.length) : filename)
// git ends ---/+++ names that contain a space with a TAB
.replace(/\t$/, '');

// Cleanup timestamps generated by the unified diff (diff command) as specified in
// https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
Expand Down