mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(discord): constrain embeds and role mentions
Respect combined embed and component limits as well as field caps. Restrict allowed mentions to validated route roles so payload text cannot notify everyone.
This commit is contained in:
1 parent
7cf507f654
commit
bfbdf3b159
3 files changed
+93
-8
No files matched your search
@@ -34,6 +34,29 @@ describe("platform contract", () => {
|
||||
}
|
||||
expect(embed!.footer).toBeDefined();
|
||||
expect(embed!.footer!.text.length).toBeLessThanOrEqual(MAX_FOOTER);
|
||||
// Discord also caps the embed's combined text at 6000 characters.
|
||||
const total =
|
||||
embed!.title!.length +
|
||||
embed!.description!.length +
|
||||
embed!.footer!.text.length +
|
||||
embed!.fields!.reduce((n, f) => n + f.name.length + f.value.length, 0);
|
||||
expect(total).toBeLessThanOrEqual(6000);
|
||||
});
|
||||
|
||||
test("discord render never lets content mention anyone but the route's roles", () => {
|
||||
const out = renderDiscord({ title: "t", mentionRoleIds: ["123456789012345678"] });
|
||||
expect(out.allowed_mentions).toEqual({ parse: [], roles: ["123456789012345678"] });
|
||||
});
|
||||
|
||||
test("discord render drops buttons whose id exceeds Discord's limit", () => {
|
||||
const out = renderDiscord({
|
||||
title: "t",
|
||||
actions: [
|
||||
{ id: `ghpr|merge|o|${"r".repeat(120)}|1`, label: "Merge", style: "primary" },
|
||||
{ id: "ghpr|close|o|r|1", label: "Close", style: "danger" },
|
||||
],
|
||||
});
|
||||
expect(out.components![0]!.components.map((c) => c.custom_id)).toEqual(["ghpr|close|o|r|1"]);
|
||||
});
|
||||
|
||||
test("telegram render stays within the 4096-char cap", () => {
|
||||
|
||||
Reference in new issue
Block a user