Skip to content

Commit

Permalink
Merge pull request #1990 from aeternity/fix-name-minus
Browse files Browse the repository at this point in the history
fix(aens): validate minus chars in name as aenode does
  • Loading branch information
davidyuk committed Jun 12, 2024
2 parents 0d90240 + 329de9e commit 1587d54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/tx/builder/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ export function nameToPunycode(maybeName: string): AensName {
if (/\p{Emoji_Presentation}/u.test(name)) {
throw new ArgumentError('aens name', 'not containing emoji', maybeName);
}
if (name[2] === '-' && name[3] === '-') {
throw new ArgumentError('aens name', 'without "-" char in both the third and fourth positions', maybeName);
}
if (name[0] === '-') {
throw new ArgumentError('aens name', 'starting with no "-" char', maybeName);
}
if (name.at(-1) === '-') {
throw new ArgumentError('aens name', 'ending with no "-" char', maybeName);
}
let punycode;
try {
const u = new URL(`http://${name}.${suffix}`);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/aens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ describe('AENS utils', () => {
expect(() => ensureName('ldiDxa1Yxy1iiTRztYEN4F8nrnfZib3Q1MllPghmst8fjJ1sI3DXzOoAddE2ETxp.chain'))
.to.throw(ArgumentError, 'aens name should be not too long, got ldiDxa1Yxy1iiTRztYEN4F8nrnfZib3Q1MllPghmst8fjJ1sI3DXzOoAddE2ETxp.chain instead');
});

it('fails if name starts or ends with minus', () => {
expect(() => ensureName('-test.chain'))
.to.throw(ArgumentError, 'aens name should be starting with no "-" char, got -test.chain instead');
expect(() => ensureName('test-.chain'))
.to.throw(ArgumentError, 'aens name should be ending with no "-" char, got test-.chain instead');
});

it('fails if name has minus at 2, 3 chars', () => {
expect(() => ensureName('te--st.chain'))
.to.throw(ArgumentError, 'aens name should be without "-" char in both the third and fourth positions, got te--st.chain instead');
});
});

describe('isAuctionName', () => {
Expand Down

0 comments on commit 1587d54

Please sign in to comment.