Skip to content

Commit

Permalink
fix: escape only pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jun 18, 2024
1 parent 05c505c commit 6e24973
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
28 changes: 1 addition & 27 deletions src/github/handlers/issue-comment-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("|", "\\|") : "-";
}
4 changes: 3 additions & 1 deletion tests/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6e24973

Please sign in to comment.