Skip to content

Commit 667599d

Browse files
authored
fix(git): commitEntry normalize user (#1813)
1 parent 8e4526d commit 667599d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/modules/git/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@ export class GitModule {
109109
const lastName = this.faker.person.lastName();
110110
const fullName = this.faker.person.fullName({ firstName, lastName });
111111
const username = this.faker.internet.userName(firstName, lastName);
112-
const user = this.faker.helpers.arrayElement([fullName, username]);
112+
let user = this.faker.helpers.arrayElement([fullName, username]);
113113
const email = this.faker.internet.email(firstName, lastName);
114114

115+
// Normalize user according to https://github.com/libgit2/libgit2/issues/5342
116+
user = user.replace(/^[\.,:;"\\']|[\<\>\n]|[\.,:;"\\']$/g, '');
117+
115118
lines.push(
116119
`Author: ${user} <${email}>`,
117120
`Date: ${this.commitDate({ refDate })}`,

test/git.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ describe('git', () => {
5454
expect(parts[0]).toMatch(/^commit [a-f0-9]+$/);
5555
if (parts.length === 7) {
5656
expect(parts[1]).toMatch(/^Merge: [a-f0-9]+ [a-f0-9]+$/);
57-
expect(parts[2]).toMatch(/^Author: [\w_\. ]+ \<[\w\.]+@[\w\.]+\>$/);
57+
expect(parts[2]).toMatch(/^Author: [^\<\>]+ \<[\w\.]+@[\w\.]+\>$/);
5858
expect(parts[3]).toMatch(/^Date: .+$/);
5959
expect(parts[4]).toBe('');
6060
expect(parts[5]).toMatch(/^\s{4}.+$/);
6161
} else {
62-
expect(parts[1]).toMatch(/^Author: [\w_\. ]+ \<[\w\.]+@[\w\.]+\>$/);
62+
expect(parts[1]).toMatch(/^Author: [^\<\>]+ \<[\w\.]+@[\w\.]+\>$/);
6363
expect(parts[2]).toMatch(/^Date: .+$/);
6464
expect(parts[3]).toBe('');
6565
expect(parts[4]).toMatch(/^\s{4}.+$/);

0 commit comments

Comments
 (0)