From 6e2497385c688c8b459cbd3032a84df77e2941bd Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 18 Jun 2024 12:26:27 +0200 Subject: [PATCH] fix: escape only pipes --- src/github/handlers/issue-comment-created.ts | 28 +------------------- tests/events.test.ts | 4 ++- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/github/handlers/issue-comment-created.ts b/src/github/handlers/issue-comment-created.ts index 66b77c2..45d4a52 100644 --- a/src/github/handlers/issue-comment-created.ts +++ b/src/github/handlers/issue-comment-created.ts @@ -31,32 +31,6 @@ export default async function issueCommentCreated(context: GitHubContext<"issue_ /** * Ensures that passed content does not break MD display within the table. */ -function escapeMarkdown(text: string) { - const replacements = { - "\\": "\\\\", - "`": "\\`", - "*": "\\*", - _: "\\_", - "{": "\\{", - "}": "\\}", - "[": "\\[", - "]": "\\]", - "(": "\\(", - ")": "\\)", - "#": "\\#", - "+": "\\+", - "-": "\\-", - ".": "\\.", - "!": "\\!", - "|": "\\|", - "~": "\\~", - ">": "\\>", - "<": "\\<", - }; - - return text.replace(/[\\`*_{}[\]()#+\-.!|~><]/g, (match) => replacements[match as keyof typeof replacements]); -} - function getContent(content: string | undefined) { - return content ? escapeMarkdown(content) : "-"; + return content ? content.replace("|", "\\|") : "-"; } diff --git a/tests/events.test.ts b/tests/events.test.ts index 4e88660..5180559 100644 --- a/tests/events.test.ts +++ b/tests/events.test.ts @@ -72,7 +72,9 @@ describe("Event related tests", () => { expect(spy.mock.calls).toEqual([ [ { - body: "### Available Commands\n\n\n| Command | Description | Example |\n|---|---|---|\n| `/help` | List all available commands. | `/help` |\n| `/command` | Plugin A | `/command \\[foo \\| bar\\]` |", + body: + "### Available Commands\n\n\n| Command | Description | Example |\n|---|---|---|\n| `/help` | List" + + " all available commands. | `/help` |\n| `/command` | Plugin A | `/command [foo \\| bar]` |", issue_number: 1, owner: "ubiquity", repo: "ubiquibot-kernel",