diff --git a/src/utils/parseENSAddress.test.ts b/src/utils/parseENSAddress.test.ts index 0cbc70c0c4..975449b601 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 bc8feaaf52..68818595fc 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] } }