From 52eca56514bd4dfce12e84e1637aaba449ef9d3d Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 17 Jan 2023 12:12:08 +0700 Subject: [PATCH 1/5] fix(internet): limit email address local part to 64 chars --- src/modules/internet/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 8f5cc8bbba6..5e7d988bf11 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -84,6 +84,8 @@ export class InternetModule { ); let localPart: string = this.userName(firstName, lastName); + // The local part of an email address is limited to 64 chars per RFC 3696 + localPart = localPart.substring(0, 64); if (options?.allowSpecialCharacters) { const usernameChars: string[] = '._-'.split(''); const specialChars: string[] = ".!#$%&'*+-/=?^_`{|}~".split(''); From ef8c0f68fe13048f2fdc8e7a4222fcfa54a329a6 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 17 Jan 2023 18:09:57 +0700 Subject: [PATCH 2/5] limit 50 --- src/modules/internet/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 5e7d988bf11..3fee1799cd0 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -85,7 +85,8 @@ export class InternetModule { let localPart: string = this.userName(firstName, lastName); // The local part of an email address is limited to 64 chars per RFC 3696 - localPart = localPart.substring(0, 64); + // We limit to 50 chars to be more realistic + localPart = localPart.substring(0, 50); if (options?.allowSpecialCharacters) { const usernameChars: string[] = '._-'.split(''); const specialChars: string[] = ".!#$%&'*+-/=?^_`{|}~".split(''); From 58dfab49c0fc663a600adeb75c4e9a1b0ac34812 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Tue, 17 Jan 2023 18:10:07 +0700 Subject: [PATCH 3/5] remove names with () in them --- src/locales/el/person/last_name.ts | 4 ++-- src/locales/fa/person/last_name.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/locales/el/person/last_name.ts b/src/locales/el/person/last_name.ts index 70634100e55..79c0caff415 100644 --- a/src/locales/el/person/last_name.ts +++ b/src/locales/el/person/last_name.ts @@ -32,7 +32,7 @@ export default [ 'Αρβανίτης', 'Αργυριάδης', 'Ασπάσιος', - 'Αυγερινός (επώνυμο)', + 'Αυγερινός', 'Βάμβας', 'Βαμβακάς', 'Βαρνακιώτης', @@ -147,7 +147,7 @@ export default [ 'Λόντος', 'Λύτρας', 'Λαγός', - 'Λαιμός (επώνυμο)', + 'Λαιμός', 'Λαμέρας', 'Λαμπρόπουλος', 'Λειβαδάς', diff --git a/src/locales/fa/person/last_name.ts b/src/locales/fa/person/last_name.ts index c012140eeb9..57d4abc996b 100644 --- a/src/locales/fa/person/last_name.ts +++ b/src/locales/fa/person/last_name.ts @@ -57,7 +57,7 @@ export default [ 'کوشکی', 'کهنمویی', 'کیان', - 'کیانی (نام خانوادگی)', + 'کیانی', 'کیمیایی', 'گل محمدی', 'گلپایگانی', From 3219bf2e15edf09970c48e0c97578cfecdfc6f43 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Wed, 18 Jan 2023 12:03:04 +0700 Subject: [PATCH 4/5] strip invalid chars from email --- src/modules/internet/index.ts | 4 ++++ test/internet.spec.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 3fee1799cd0..30e081baa39 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -84,6 +84,10 @@ export class InternetModule { ); let localPart: string = this.userName(firstName, lastName); + // Strip any special characters from the local part of the email address + // This could happen if invalid chars are passed in manually in the firstName/lastName + localPart = localPart.replace(/[^A-Za-z0-9._+\-\']+/g, ''); + // The local part of an email address is limited to 64 chars per RFC 3696 // We limit to 50 chars to be more realistic localPart = localPart.substring(0, 50); diff --git a/test/internet.spec.ts b/test/internet.spec.ts index 11cbb60e7c2..16b6a804196 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -156,6 +156,25 @@ describe('internet', () => { expect(faker.definitions.internet.free_email).toContain(suffix); }); + it('should return a valid email for very long names', () => { + const longFirstName = + 'Elizabeth Alexandra Mary Jane Annabel Victoria'; + const longSurname = 'Smith Jones Davidson Brown White Greene Black'; + const email = faker.internet.email(longFirstName, longSurname); + // should truncate to 50 chars + // e.g. ElizabethAlexandraMaryJaneAnnabelVictoria.SmithJon@yahoo.com + expect(email).toSatisfy(validator.isEmail); + const localPart = email.split('@')[0]; + expect(localPart.length).toBeLessThanOrEqual(50); + }); + + it('should return a valid email for names with invalid chars', () => { + const email = faker.internet.email('Matthew (Matt)', 'Smith'); + // should strip invalid chars + // e.g. MatthewMatt_Smith@yahoo.com + expect(email).toSatisfy(validator.isEmail); + }); + it('should return an email with special characters', () => { const email = faker.internet.email('Mike', 'Smith', null, { allowSpecialCharacters: true, From 28bc97c6c6f0ef11a6b8b845b23ed1a890b67b05 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Thu, 19 Jan 2023 20:04:27 +0700 Subject: [PATCH 5/5] dont allow ' in emails --- src/modules/internet/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 30e081baa39..a37484fc255 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -86,7 +86,7 @@ export class InternetModule { let localPart: string = this.userName(firstName, lastName); // Strip any special characters from the local part of the email address // This could happen if invalid chars are passed in manually in the firstName/lastName - localPart = localPart.replace(/[^A-Za-z0-9._+\-\']+/g, ''); + localPart = localPart.replace(/[^A-Za-z0-9._+\-]+/g, ''); // The local part of an email address is limited to 64 chars per RFC 3696 // We limit to 50 chars to be more realistic