mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: Enforce limit of URLs for link buttons (#11011)
feat: enforce limit of URLs for link buttons
This commit is contained in:
@@ -30,7 +30,7 @@ describe('Button Components', () => {
|
|||||||
button.toJSON();
|
button.toJSON();
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
|
|
||||||
expect(() => new LinkButtonBuilder().setURL('https://google.com')).not.toThrowError();
|
expect(() => new LinkButtonBuilder().setLabel('label').setURL('https://google.com').toJSON()).not.toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GIVEN invalid fields THEN build does throw', () => {
|
test('GIVEN invalid fields THEN build does throw', () => {
|
||||||
@@ -61,6 +61,13 @@ describe('Button Components', () => {
|
|||||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setDisabled(0).toJSON()).toThrowError();
|
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setDisabled(0).toJSON()).toThrowError();
|
||||||
// @ts-expect-error: Invalid emoji
|
// @ts-expect-error: Invalid emoji
|
||||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('foo').toJSON()).toThrowError();
|
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('foo').toJSON()).toThrowError();
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
new LinkButtonBuilder()
|
||||||
|
.setLabel('label')
|
||||||
|
.setURL(`https://google.com/${'a'.repeat(512)}`)
|
||||||
|
.toJSON(),
|
||||||
|
).toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GiVEN valid input THEN valid JSON outputs are given', () => {
|
test('GiVEN valid input THEN valid JSON outputs are given', () => {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const buttonDangerPredicate = buttonCustomIdPredicateBase.extend({ style: z.lite
|
|||||||
|
|
||||||
const buttonLinkPredicate = buttonPredicateBase.extend({
|
const buttonLinkPredicate = buttonPredicateBase.extend({
|
||||||
style: z.literal(ButtonStyle.Link),
|
style: z.literal(ButtonStyle.Link),
|
||||||
url: z.url({ protocol: /^(?:https?|discord)$/ }),
|
url: z.url({ protocol: /^(?:https?|discord)$/ }).max(512),
|
||||||
emoji: emojiPredicate.optional(),
|
emoji: emojiPredicate.optional(),
|
||||||
label: labelPredicate,
|
label: labelPredicate,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user