Skip to content

Commit

Permalink
fix(git): commitEntry normalize user (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Feb 4, 2023
1 parent 8e4526d commit 667599d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/modules/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ export class GitModule {
const lastName = this.faker.person.lastName();
const fullName = this.faker.person.fullName({ firstName, lastName });
const username = this.faker.internet.userName(firstName, lastName);
const user = this.faker.helpers.arrayElement([fullName, username]);
let user = this.faker.helpers.arrayElement([fullName, username]);
const email = this.faker.internet.email(firstName, lastName);

// Normalize user according to https://github.com/libgit2/libgit2/issues/5342
user = user.replace(/^[\.,:;"\\']|[\<\>\n]|[\.,:;"\\']$/g, '');

lines.push(
`Author: ${user} <${email}>`,
`Date: ${this.commitDate({ refDate })}`,
Expand Down
4 changes: 2 additions & 2 deletions test/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ describe('git', () => {
expect(parts[0]).toMatch(/^commit [a-f0-9]+$/);
if (parts.length === 7) {
expect(parts[1]).toMatch(/^Merge: [a-f0-9]+ [a-f0-9]+$/);
expect(parts[2]).toMatch(/^Author: [\w_\. ]+ \<[\w\.]+@[\w\.]+\>$/);
expect(parts[2]).toMatch(/^Author: [^\<\>]+ \<[\w\.]+@[\w\.]+\>$/);
expect(parts[3]).toMatch(/^Date: .+$/);
expect(parts[4]).toBe('');
expect(parts[5]).toMatch(/^\s{4}.+$/);
} else {
expect(parts[1]).toMatch(/^Author: [\w_\. ]+ \<[\w\.]+@[\w\.]+\>$/);
expect(parts[1]).toMatch(/^Author: [^\<\>]+ \<[\w\.]+@[\w\.]+\>$/);
expect(parts[2]).toMatch(/^Date: .+$/);
expect(parts[3]).toBe('');
expect(parts[4]).toMatch(/^\s{4}.+$/);
Expand Down

0 comments on commit 667599d

Please sign in to comment.