diff options
| author | Matt Mayer <[email protected]> | 2023-01-21 02:24:06 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-20 20:24:06 +0100 |
| commit | 1e4e8699e59f3b5b9c1e1d6ad9b89ee4cc254e95 (patch) | |
| tree | e1f3fd268f970824639b0e94224e0dfc46c38c86 /src/modules | |
| parent | dfa647dc07ea25f962c4df913bae2de082e8acc4 (diff) | |
| download | faker-1e4e8699e59f3b5b9c1e1d6ad9b89ee4cc254e95.tar.xz faker-1e4e8699e59f3b5b9c1e1d6ad9b89ee4cc254e95.zip | |
fix(internet): fix invalid emails in some locales (#1746)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/internet/index.ts | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index f7f022ac..d1af8ebe 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -91,6 +91,13 @@ 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); if (options?.allowSpecialCharacters) { const usernameChars: string[] = '._-'.split(''); const specialChars: string[] = ".!#$%&'*+-/=?^_`{|}~".split(''); |
