From eb4c305eff00924d84705a8df17a218afdafdc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ku=C4=87mierz?= Date: Sat, 7 Nov 2020 17:19:01 +0100 Subject: [PATCH] fix(ens): support ens names with dashes in them * fix: parseENSAddress #1200 * fix: lint error #1200 * fix: parseENSAddress - allow to match domains with twice characters; disallow more than once dash next to each other --- src/utils/parseENSAddress.test.ts | 5 +++++ src/utils/parseENSAddress.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/parseENSAddress.test.ts b/src/utils/parseENSAddress.test.ts index 0cbc70c0c43..975449b6017 100644 --- a/src/utils/parseENSAddress.test.ts +++ b/src/utils/parseENSAddress.test.ts @@ -10,5 +10,10 @@ describe('parseENSAddress', () => { expect(parseENSAddress('abso.lutely.eth')).toEqual({ ensName: 'abso.lutely.eth', ensPath: undefined }) expect(parseENSAddress('eth')).toEqual(undefined) expect(parseENSAddress('eth/hello-world')).toEqual(undefined) + expect(parseENSAddress('hello-world.eth')).toEqual({ ensName: 'hello-world.eth', ensPath: undefined }) + expect(parseENSAddress('-prefix-dash.eth')).toEqual(undefined) + expect(parseENSAddress('suffix-dash-.eth')).toEqual(undefined) + expect(parseENSAddress('it.eth')).toEqual({ ensName: 'it.eth', ensPath: undefined }) + expect(parseENSAddress('only-single--dash.eth')).toEqual(undefined) }) }) diff --git a/src/utils/parseENSAddress.ts b/src/utils/parseENSAddress.ts index bc8feaaf520..68818595fce 100644 --- a/src/utils/parseENSAddress.ts +++ b/src/utils/parseENSAddress.ts @@ -1,7 +1,7 @@ -const ENS_NAME_REGEX = /^(([a-zA-Z0-9]+\.)+)eth(\/.*)?$/ +const ENS_NAME_REGEX = /^(([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\.)+)eth(\/.*)?$/ export function parseENSAddress(ensAddress: string): { ensName: string; ensPath: string | undefined } | undefined { const match = ensAddress.match(ENS_NAME_REGEX) if (!match) return undefined - return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[3] } + return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[4] } }