From 1208e5cb6f1630c62843ad4b034311a3553b30ef Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:27:05 +0530 Subject: [PATCH] fix: drop the TAB git adds after file names with spaces --- src/__tests__/diff-parser-tests.ts | 16 ++++++++++++++++ src/diff-parser.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/__tests__/diff-parser-tests.ts b/src/__tests__/diff-parser-tests.ts index dde2778e..5d07ee1b 100644 --- a/src/__tests__/diff-parser-tests.ts +++ b/src/__tests__/diff-parser-tests.ts @@ -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' + diff --git a/src/diff-parser.ts b/src/diff-parser.ts index 83d9c630..0f9c3de7 100644 --- a/src/diff-parser.ts +++ b/src/diff-parser.ts @@ -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