Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/controller-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Update `normalizeEnsName` regex to allow ENS names with 3 or more characters (previously required 7 or more) ([#8510](https://github.com/MetaMask/core/pull/8510))
- Update default Sei Mainnet block explorer URL from `seitrace.com` to `seiscan.io` ([#8545](https://github.com/MetaMask/core/pull/8545))

## [11.20.0]
Expand Down
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)) {
Comment thread
NidhiKJha marked this conversation as resolved.
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