mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
fix(telegram): render HTML with markdown-it and strip HTML from Discord bodies
This commit is contained in:
parent
ea049e28c9
commit
9899cd01bf
7 changed files with 90 additions and 18 deletions
|
|
@ -523,6 +523,46 @@ describe("limits and localization", () => {
|
|||
expect(msg.fields!.every((f) => f.value.length <= 1024)).toBe(true);
|
||||
expect(msg.description!.length).toBe(4096);
|
||||
});
|
||||
|
||||
it("strips HTML tags from issue and PR bodies", () => {
|
||||
const issue = formatEvent(
|
||||
route,
|
||||
event("issues", {
|
||||
action: "opened",
|
||||
issue: {
|
||||
number: 3,
|
||||
title: "Bug",
|
||||
html_url: "https://github.com/acme/widget/issues/3",
|
||||
body: "Use <b>bold</b> and <code>code</code>",
|
||||
},
|
||||
repository: repo,
|
||||
sender,
|
||||
}),
|
||||
);
|
||||
expect(issue.description).toContain("Use bold and code");
|
||||
expect(issue.description).not.toContain("<b>");
|
||||
expect(issue.description).not.toContain("<code>");
|
||||
|
||||
const pr = formatEvent(
|
||||
route,
|
||||
event("pull_request", {
|
||||
action: "opened",
|
||||
pull_request: {
|
||||
number: 7,
|
||||
title: "Add feature",
|
||||
state: "open",
|
||||
html_url: "https://github.com/acme/widget/pull/7",
|
||||
body: 'Fixes <a href="https://x.example">the bug</a>',
|
||||
head: { ref: "feat" },
|
||||
base: { ref: "main" },
|
||||
},
|
||||
repository: repo,
|
||||
sender,
|
||||
}),
|
||||
);
|
||||
expect(pr.description).toContain("Fixes the bug");
|
||||
expect(pr.description).not.toContain("<a ");
|
||||
});
|
||||
});
|
||||
|
||||
describe("forge source branding", () => {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,20 @@ describe("telegram renderNeutralMessage", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("keeps query strings and parens intact in link URLs", () => {
|
||||
const out = renderNeutralMessage({
|
||||
title: "acme/widget: t",
|
||||
description:
|
||||
"[View](https://github.com/acme/widget/compare/a?w=1&diff=split) and " +
|
||||
"[wiki](https://en.wikipedia.org/wiki/Foo_(bar))",
|
||||
});
|
||||
expect(out).toContain(
|
||||
'<a href="https://github.com/acme/widget/compare/a?w=1&diff=split">View</a>',
|
||||
);
|
||||
expect(out).toContain('<a href="https://en.wikipedia.org/wiki/Foo_(bar)">wiki</a>');
|
||||
expect(out).not.toContain("&amp;");
|
||||
});
|
||||
|
||||
it("formats ISO timestamps into a readable UTC string", () => {
|
||||
const out = renderNeutralMessage({
|
||||
title: "acme/widget: t",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue