Skip to content

Commit

Permalink
fix: escape text for slack api
Browse files Browse the repository at this point in the history
  • Loading branch information
uffy committed Dec 26, 2024
1 parent 2fa2484 commit cb95e18
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion next/api/src/integration/slack/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ export class Message {
}
}

function getTicketLink(ticket: Ticket): string {
function escapeSlackCharacters(text:string) {
return text
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}

function getTicketLink(ticket:Ticket) {
let title = ticket.title;
if (title.length > 50) {
title = title.slice(0, 47) + '...';
}
// Escape special characters in the title
title = escapeSlackCharacters(title);

return `<${ticket.getUrl()}|*#${ticket.nid}: ${title}*>`;
}

Expand Down

0 comments on commit cb95e18

Please sign in to comment.