Commit eb4c305e authored by Grzegorz Kućmierz's avatar Grzegorz Kućmierz Committed by GitHub

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
parent d9825622
......@@ -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)
})
})
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] }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment