Skip to content

Commit ea6c511

Browse files
Shinigami92matthewmayer
authored andcommitted
fix(git): commitEntry normalize user (faker-js#1813)
1 parent b193fc9 commit ea6c511

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/modules/git/index.ts

Lines changed: 4 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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)