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; }