From e1a40d7f3371968d1a8619d62ab0f1d78ff8bf6c Mon Sep 17 00:00:00 2001 From: Dharya-dev Date: Tue, 26 May 2026 02:57:48 +0530 Subject: [PATCH] fix(utils): preserve author names containing commas in git log parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The eager VCS strategy parses git log output in the format t:,a:. When splitting on comma to separate the timestamp and author fields, author names containing commas (e.g., 'Doe, Jane' or 'Smith, Jr.') were silently truncated — only the text before the first comma in the name was kept. This replaces split(',') with indexOf(',a:') to locate the known separator between the timestamp and author fields, correctly preserving the full author name regardless of commas it may contain. --- .../src/vcs/__tests__/gitUtils.test.ts | 18 ++++++++++++++++++ packages/docusaurus-utils/src/vcs/gitUtils.ts | 10 ++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-utils/src/vcs/__tests__/gitUtils.test.ts b/packages/docusaurus-utils/src/vcs/__tests__/gitUtils.test.ts index fd817e579eae..48645adf7f55 100644 --- a/packages/docusaurus-utils/src/vcs/__tests__/gitUtils.test.ts +++ b/packages/docusaurus-utils/src/vcs/__tests__/gitUtils.test.ts @@ -396,6 +396,24 @@ describe('commit info APIs', () => { } `); }); + + it('preserves author names containing commas', async () => { + const {repoDir, git} = await createGitRepoEmpty(); + + await git.commitFile('comma-author.txt', { + fileContent: 'content', + commitMessage: 'Commit by author with comma in name', + commitDate: '2024-01-15', + commitAuthor: 'Doe, Jane ', + }); + + const filesInfo = await getGitRepositoryFilesInfo(repoDir); + const fileInfo = filesInfo.get('comma-author.txt'); + + expect(fileInfo).toBeDefined(); + expect(fileInfo!.creation.author).toBe('Doe, Jane'); + expect(fileInfo!.lastUpdate.author).toBe('Doe, Jane'); + }); }); }); diff --git a/packages/docusaurus-utils/src/vcs/gitUtils.ts b/packages/docusaurus-utils/src/vcs/gitUtils.ts index a1c13997401a..9a2c97aab09c 100644 --- a/packages/docusaurus-utils/src/vcs/gitUtils.ts +++ b/packages/docusaurus-utils/src/vcs/gitUtils.ts @@ -491,11 +491,13 @@ The command exited with code ${result.exitCode}: ${result.stderr}`, for (const logLine of logLines) { if (logLine.startsWith('t:')) { // t:,a: - const [timestampStr, authorStr] = logLine.split(',') as [string, string]; - const timestamp = Number.parseInt(timestampStr.slice(2), 10) * 1000; - const author = authorStr.slice(2); + // We can't use split(',') because author names may contain commas + // (e.g., "Last, First" or "John Doe, Jr.") + const separatorIndex = logLine.indexOf(',a:'); + const timestampStr = logLine.slice(2, separatorIndex); + const author = logLine.slice(separatorIndex + 3); - runningDate = timestamp; + runningDate = Number.parseInt(timestampStr, 10) * 1000; runningAuthor = author; }