Skip to content

Commit

Permalink
fix(ens): support ens names with dashes in them
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gkucmierz authored Nov 7, 2020
1 parent d982562 commit eb4c305
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/utils/parseENSAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
4 changes: 2 additions & 2 deletions src/utils/parseENSAddress.ts
Original file line number Diff line number Diff line change
@@ -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] }
}

1 comment on commit eb4c305

@vercel
Copy link

@vercel vercel bot commented on eb4c305 Nov 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.