Skip to content

Commit

Permalink
fix: [nautilus-cyberneering#197] replace regexp by external pakckage …
Browse files Browse the repository at this point in the history
…for email valitation

The new validator is more restrict.
  • Loading branch information
josecelano committed Jun 8, 2022
1 parent 455bbbb commit 16b7726
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 19 deletions.
26 changes: 13 additions & 13 deletions __tests__/unit/email-address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,9 @@ describe('EmailAddress', () => {
it('should validate email addresses', () => {
const validEmails = [
'Abc@example.com',
'Abc@example.com.',
'Abc@10.42.0.1',
'user@localserver',
'Abc.123@example.com',
'user+mailbox/department=shipping@example.com',
'"very.(),:;<>[]".VERY."very@\\ "very".unusual"@strange.example.com',
"!#$%&'*+-/=?^_`.{|}~@example.com",
'"()<>[]:,;@\\"!#$%&\'-/=?^_`{}| ~.a"@example.org',
'"Abc@def"@example.com',
'"Fred Bloggs"@example.com',
'"Joe.\\Blow"@example.com',
'Loïc.Accentué@voilà.fr',
'user@[IPv6:2001:DB8::1]',
'" "@example.org'
"!#$%&'*+-/=?^_`.{|}~@example.com"
]

for (const email of validEmails) {
Expand All @@ -59,7 +48,18 @@ describe('EmailAddress', () => {
'this is"notallowed@example.com',
'this still"not\\allowed@example.com',
'john..doe@example.com',
'john.doe@example..com'
'john.doe@example..com',
'Abc@example.com.',
'Abc@10.42.0.1',
'user@localserver',
'"very.(),:;<>[]".VERY."very@\\ "very".unusual"@strange.example.com',
'"()<>[]:,;@\\"!#$%&\'-/=?^_`{}| ~.a"@example.org',
'"Abc@def"@example.com',
'"Fred Bloggs"@example.com',
'"Joe.\\Blow"@example.com',
'Loïc.Accentué@voilà.fr',
'user@[IPv6:2001:DB8::1]',
'" "@example.org'
]

for (const email of invalidEmails) {
Expand Down
65 changes: 63 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/email-address.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as EmailValidator from 'email-validator'

/*
* Wrapper for RFC5322 email address.
*
Expand Down Expand Up @@ -85,7 +87,5 @@ export class EmailAddress {
}

export function emailIsValid(email: string): boolean {
return /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>().,;\s@"]+\.{0,1})+([^<>().,;:\s@"]{2,}|[\d.]+))$/.test(
email
)
return EmailValidator.validate(email)
}

0 comments on commit 16b7726

Please sign in to comment.