Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/controller-utils/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe('util', () => {
expect(invalid).toBeNull();
invalid = util.normalizeEnsName('@metamask.eth');
expect(invalid).toBeNull();
invalid = util.normalizeEnsName('foobar.eth');
invalid = util.normalizeEnsName('fo.eth');
expect(invalid).toBeNull();
});

Expand All @@ -617,9 +617,9 @@ describe('util', () => {
expect(invalid).toBeNull();
});

it('should return null with invalid 2LD and valid 3LD', async () => {
const invalid = util.normalizeEnsName('foo.barbaz.eth');
expect(invalid).toBeNull();
it('should normalize with valid 3LD', async () => {
const valid = util.normalizeEnsName('foo.barbaz.eth');
expect(valid).toBe('foo.barbaz.eth');
});

it('should return null with invalid TLD', async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/controller-utils/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ export function normalizeEnsName(ensName: string): string | null {
try {
const normalized = ensNamehash.normalize(ensName.trim());
// this regex is only sufficient with the above call to ensNamehash.normalize
// TODO: change 7 in regex to 3 when shorter ENS domains are live
if (normalized.match(/^(([\w\d-]+)\.)*[\w\d-]{7,}\.(eth|test)$/u)) {
if (normalized.match(/^(([\w\d-]+)\.)*[\w\d-]{3,}\.(eth|test)$/u)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a CHANGELOG entry for this change?

return normalized;
}
} catch {
Expand Down
19 changes: 17 additions & 2 deletions packages/ens-controller/src/EnsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,26 @@ describe('EnsController', () => {
messenger: ensControllerMessenger,
});
expect(() => {
controller.set('0x1', 'foo.eth', address1);
}).toThrow('Invalid ENS name: foo.eth');
controller.set('0x1', 'fo.eth', address1);
}).toThrow('Invalid ENS name: fo.eth');
expect(controller.state).toStrictEqual(defaultState);
});

it('should allow 3 character ENS names', () => {
const rootMessenger = getRootMessenger();
const ensControllerMessenger = getEnsControllerMessenger(rootMessenger);
const controller = new EnsController({
messenger: ensControllerMessenger,
});

expect(controller.set('0x1', 'foo.eth', address1)).toBe(true);
expect(controller.state.ensEntries['0x1']['foo.eth']).toStrictEqual({
address: address1Checksum,
chainId: '0x1',
ensName: 'foo.eth',
});
});

it('should throw on attempt to set invalid ENS entry: address', () => {
const rootMessenger = getRootMessenger();
const ensControllerMessenger = getEnsControllerMessenger(rootMessenger);
Expand Down
Loading