From c88b555410e7eb6f9ded4648bd6236c9f653c731 Mon Sep 17 00:00:00 2001 From: Hailey Date: Fri, 20 Sep 2024 14:10:34 -0700 Subject: Validate TLD in signup (#5426) * add lib * add validation * log * add some common typos * add tests * reset hasWarned state on edit * shorten path * Move test file, adjust regex, add test * Get real nit picky --------- Co-authored-by: Eric Bailey --- src/lib/strings/__tests__/email.test.ts | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/lib/strings/__tests__/email.test.ts (limited to 'src/lib/strings/__tests__/email.test.ts') diff --git a/src/lib/strings/__tests__/email.test.ts b/src/lib/strings/__tests__/email.test.ts new file mode 100644 index 000000000..4dfda658f --- /dev/null +++ b/src/lib/strings/__tests__/email.test.ts @@ -0,0 +1,82 @@ +import {describe, expect, it} from '@jest/globals' +import tldts from 'tldts' + +import {isEmailMaybeInvalid} from '#/lib/strings/email' + +describe('emailTypoChecker', () => { + const invalidCases = [ + 'gnail.com', + 'gnail.co', + 'gmaill.com', + 'gmaill.co', + 'gmai.com', + 'gmai.co', + 'gmal.com', + 'gmal.co', + 'gmail.co', + 'iclod.com', + 'iclod.co', + 'outllok.com', + 'outllok.co', + 'outlook.co', + 'yaoo.com', + 'yaoo.co', + 'yaho.com', + 'yaho.co', + 'yahooo.com', + 'yahooo.co', + 'yahoo.co', + 'hithere.jul', + 'agpowj.notshop', + 'thisisnot.avalid.tld.nope', + // old tld for czechoslovakia + 'czechoslovakia.cs', + // tlds that cbs was registering in 2024 but cancelled + 'liveon.cbs', + 'its.showtime', + ] + const validCases = [ + 'gmail.com', + // subdomains (tests end of string) + 'gnail.com.test.com', + 'outlook.com', + 'yahoo.com', + 'icloud.com', + 'firefox.com', + 'firefox.co', + 'hello.world.com', + 'buy.me.a.coffee.shop', + 'mayotte.yt', + 'aland.ax', + 'bouvet.bv', + 'uk.gb', + 'chad.td', + 'somalia.so', + 'plane.aero', + 'cute.cat', + 'together.coop', + 'findme.jobs', + 'nightatthe.museum', + 'industrial.mil', + 'czechrepublic.cz', + 'lovakia.sk', + // new gtlds in 2024 + 'whatsinyour.locker', + 'letsmakea.deal', + 'skeet.now', + 'everyone.みんな', + 'bourgeois.lifestyle', + 'california.living', + 'skeet.ing', + 'listeningto.music', + 'createa.meme', + ] + + it.each(invalidCases)(`should be invalid: abcde@%s`, domain => { + expect(isEmailMaybeInvalid(`abcde@${domain}`, tldts)).toEqual(true) + }) + + it.each(validCases)(`should be valid: abcde@%s`, domain => { + expect(isEmailMaybeInvalid(`abcde@${domain}`, tldts)).toEqual(false) + }) +}) -- cgit 1.4.1