aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Mayer <[email protected]>2023-03-09 04:51:28 +0700
committerGitHub <[email protected]>2023-03-08 21:51:28 +0000
commitf8926c7b1311e5c1e617289f9ee3760b522bea3f (patch)
tree8de628ad334a2fcced94182388cd7fbf833f88a1
parent4f14533418e23496fa463f08e8276cb230dc7643 (diff)
downloadfaker-f8926c7b1311e5c1e617289f9ee3760b522bea3f.tar.xz
faker-f8926c7b1311e5c1e617289f9ee3760b522bea3f.zip
fix(internet): filter banned dots from email addresses (#1883)
-rw-r--r--src/modules/internet/index.ts7
-rw-r--r--test/internet.spec.ts24
2 files changed, 31 insertions, 0 deletions
diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts
index 2623f8b3..c0355209 100644
--- a/src/modules/internet/index.ts
+++ b/src/modules/internet/index.ts
@@ -109,6 +109,13 @@ export class InternetModule {
);
}
+ // local parts may not contain two or more consecutive . characters
+ localPart = localPart.replace(/\.{2,}/g, '.');
+
+ // local parts may not start with or end with a . character
+ localPart = localPart.replace(/^\./, '');
+ localPart = localPart.replace(/\.$/, '');
+
return `${localPart}@${provider}`;
}
diff --git a/test/internet.spec.ts b/test/internet.spec.ts
index c2d8fcb2..0730f384 100644
--- a/test/internet.spec.ts
+++ b/test/internet.spec.ts
@@ -133,6 +133,30 @@ describe('internet', () => {
expect(faker.definitions.internet.free_email).toContain(suffix);
});
+ it('should not allow an email that starts or ends with a .', () => {
+ const email = faker.internet.email('...Aiden...', '...Doe...');
+
+ expect(email).toBeTruthy();
+ expect(email).toBeTypeOf('string');
+ expect(email).toSatisfy(validator.isEmail);
+
+ const [prefix] = email.split('@');
+ expect(prefix).not.toMatch(/^\./);
+ expect(prefix).not.toMatch(/\.$/);
+ });
+
+ it('should not allow an email with multiple dots', () => {
+ const email = faker.internet.email('Ai....den');
+
+ expect(email).toBeTruthy();
+ expect(email).toBeTypeOf('string');
+ expect(email).toSatisfy(validator.isEmail);
+
+ const [prefix] = email.split('@');
+ //expect it not to contain multiple .s
+ expect(prefix).not.toMatch(/\.{2,}/);
+ });
+
it('should return an email with given firstName and lastName', () => {
const email = faker.internet.email('Aiden', 'Harann');