Skip to content

Commit

Permalink
fix: escape slack chars in links
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Sep 6, 2022
1 parent fb6a6f7 commit 69eedb1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/slack/utils.ts
Expand Up @@ -3,8 +3,16 @@ import type { RepoContext } from '../context/repoContext';
import type { CommitFromRestEndpoint } from '../events/commit-handlers/utils/fetchCommit';
import type { PullRequestWithDecentData } from '../events/pr-handlers/utils/PullRequestData';

// https://api.slack.com/reference/surfaces/formatting#escaping
export const escapeText = (text: string): string => {
return text
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;');
};

export const createLink = (url: string, text: string): string => {
return `<${url}|${text}>`;
return `<${url}|${escapeText(text)}>`;
};

export const createPrLink = (
Expand Down

0 comments on commit 69eedb1

Please sign in to comment.