File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,6 +109,13 @@ export class InternetModule {
109109 ) ;
110110 }
111111
112+ // local parts may not contain two or more consecutive . characters
113+ localPart = localPart . replace ( / \. { 2 , } / g, '.' ) ;
114+
115+ // local parts may not start with or end with a . character
116+ localPart = localPart . replace ( / ^ \. / , '' ) ;
117+ localPart = localPart . replace ( / \. $ / , '' ) ;
118+
112119 return `${ localPart } @${ provider } ` ;
113120 }
114121
Original file line number Diff line number Diff line change @@ -133,6 +133,30 @@ describe('internet', () => {
133133 expect ( faker . definitions . internet . free_email ) . toContain ( suffix ) ;
134134 } ) ;
135135
136+ it ( 'should not allow an email that starts or ends with a .' , ( ) => {
137+ const email = faker . internet . email ( '...Aiden...' , '...Doe...' ) ;
138+
139+ expect ( email ) . toBeTruthy ( ) ;
140+ expect ( email ) . toBeTypeOf ( 'string' ) ;
141+ expect ( email ) . toSatisfy ( validator . isEmail ) ;
142+
143+ const [ prefix ] = email . split ( '@' ) ;
144+ expect ( prefix ) . not . toMatch ( / ^ \. / ) ;
145+ expect ( prefix ) . not . toMatch ( / \. $ / ) ;
146+ } ) ;
147+
148+ it ( 'should not allow an email with multiple dots' , ( ) => {
149+ const email = faker . internet . email ( 'Ai....den' ) ;
150+
151+ expect ( email ) . toBeTruthy ( ) ;
152+ expect ( email ) . toBeTypeOf ( 'string' ) ;
153+ expect ( email ) . toSatisfy ( validator . isEmail ) ;
154+
155+ const [ prefix ] = email . split ( '@' ) ;
156+ //expect it not to contain multiple .s
157+ expect ( prefix ) . not . toMatch ( / \. { 2 , } / ) ;
158+ } ) ;
159+
136160 it ( 'should return an email with given firstName and lastName' , ( ) => {
137161 const email = faker . internet . email ( 'Aiden' , 'Harann' ) ;
138162
You can’t perform that action at this time.
0 commit comments