Skip to content

Commit f2fec91

Browse files
authored
feat: Enforce limit of URLs for link buttons (#11011)
feat: enforce limit of URLs for link buttons
1 parent 90b3692 commit f2fec91

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/builders/__tests__/components/button.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Button Components', () => {
3030
button.toJSON();
3131
}).not.toThrowError();
3232

33-
expect(() => new LinkButtonBuilder().setURL('https://google.com')).not.toThrowError();
33+
expect(() => new LinkButtonBuilder().setLabel('label').setURL('https://google.com').toJSON()).not.toThrowError();
3434
});
3535

3636
test('GIVEN invalid fields THEN build does throw', () => {
@@ -61,6 +61,13 @@ describe('Button Components', () => {
6161
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setDisabled(0).toJSON()).toThrowError();
6262
// @ts-expect-error: Invalid emoji
6363
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('foo').toJSON()).toThrowError();
64+
65+
expect(() =>
66+
new LinkButtonBuilder()
67+
.setLabel('label')
68+
.setURL(`https://google.com/${'a'.repeat(512)}`)
69+
.toJSON(),
70+
).toThrowError();
6471
});
6572

6673
test('GiVEN valid input THEN valid JSON outputs are given', () => {

packages/builders/src/components/Assertions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const buttonDangerPredicate = buttonCustomIdPredicateBase.extend({ style: z.lite
3232

3333
const buttonLinkPredicate = buttonPredicateBase.extend({
3434
style: z.literal(ButtonStyle.Link),
35-
url: z.url({ protocol: /^(?:https?|discord)$/ }),
35+
url: z.url({ protocol: /^(?:https?|discord)$/ }).max(512),
3636
emoji: emojiPredicate.optional(),
3737
label: labelPredicate,
3838
});

0 commit comments

Comments
 (0)