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
This commit is contained in:
parent
d9825622f1
commit
eb4c305eff
@ -10,5 +10,10 @@ describe('parseENSAddress', () => {
|
|||||||
expect(parseENSAddress('abso.lutely.eth')).toEqual({ ensName: 'abso.lutely.eth', ensPath: undefined })
|
expect(parseENSAddress('abso.lutely.eth')).toEqual({ ensName: 'abso.lutely.eth', ensPath: undefined })
|
||||||
expect(parseENSAddress('eth')).toEqual(undefined)
|
expect(parseENSAddress('eth')).toEqual(undefined)
|
||||||
expect(parseENSAddress('eth/hello-world')).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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -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 {
|
export function parseENSAddress(ensAddress: string): { ensName: string; ensPath: string | undefined } | undefined {
|
||||||
const match = ensAddress.match(ENS_NAME_REGEX)
|
const match = ensAddress.match(ENS_NAME_REGEX)
|
||||||
if (!match) return undefined
|
if (!match) return undefined
|
||||||
return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[3] }
|
return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[4] }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user