Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aens): validate minus chars in name as aenode does #1990

Merged
merged 1 commit into from
Jun 12, 2024
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
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
Loading