diff --git a/src/utils.spec.js b/src/utils.spec.js index f1f35941a..afeb14a83 100644 --- a/src/utils.spec.js +++ b/src/utils.spec.js @@ -5,7 +5,9 @@ import { validateSchema, getScores, getVp, - getFormattedAddress + getFormattedAddress, + getEnsOwner, + getEnsTextRecord } from './utils'; vi.mock('cross-fetch', async () => { @@ -611,4 +613,18 @@ describe('utils', () => { expect(result).not.toBe(true); }); }); + + describe('getEnsOwner', () => { + test('should return null when the ENS is not valid', () => { + // special hidden characters after the k + expect(getEnsOwner('elonmusk‍‍.eth')).resolves.toBe(null); + }); + }); + + describe('getEnsTextRecord', () => { + test('should return null when the ENS is not valid', () => { + // special hidden characters after the k + expect(getEnsTextRecord('elonmusk‍‍.eth')).resolves.toBe(null); + }); + }); }); diff --git a/src/utils.ts b/src/utils.ts index 2feda326e..4990db06b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -544,7 +544,14 @@ export async function getEnsTextRecord( ...multicallOptions } = options; - const ensHash = namehash(ensNormalize(ens)); + let ensHash: string; + + try { + ensHash = namehash(ensNormalize(ens)); + } catch (e: any) { + return null; + } + const provider = getProvider(network, { broviderUrl }); const calls = [ @@ -592,9 +599,17 @@ export async function getEnsOwner( ['function owner(bytes32) view returns (address)'], provider ); + + let ensHash: string; + + try { + ensHash = namehash(ensNormalize(ens)); + } catch (e: any) { + return null; + } + const ensNameWrapper = options.ensNameWrapper || networks[network].ensNameWrapper; - const ensHash = namehash(ensNormalize(ens)); let owner = await ensRegistry.owner(ensHash); // If owner is the ENSNameWrapper contract, resolve the owner of the name if (owner === ensNameWrapper) {