Skip to content

Commit f974860

Browse files
authored
Properly escape backticks in error messages (#167)
1 parent 281dae2 commit f974860

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import mdEscape = require("markdown-escape");
1111
import randomSeed = require("random-seed");
1212
import { getErrorMessageFromStack, getHash, getHashForStack } from "./utils/hashStackTrace";
1313
import { createCopyingOverlayFS, createTempOverlayFS, OverlayBaseFS } from "./utils/overlayFS";
14+
import { asMarkdownInlineCode } from "./utils/markdownUtils";
1415

1516
interface Params {
1617
/**
@@ -434,7 +435,7 @@ ${summary.replayScript}
434435
`;
435436
// No url means is user test repo
436437
if (!summary.repo.url) {
437-
text += `# Manually download user test \`${summary.repo.name}\`\n`;
438+
text += `# Manually download user test ${asMarkdownInlineCode(summary.repo.name)}\n`;
438439
}
439440
else {
440441
text += `git clone ${summary.repo.url} --recurse-submodules\n`;
@@ -512,7 +513,7 @@ ${summary.replayScript}
512513
`;
513514
// No url means is user test repo
514515
if (!summary.repo.url) {
515-
text += `# Manually download user test \`${summary.repo.name}\`\n`;
516+
text += `# Manually download user test ${asMarkdownInlineCode(summary.repo.name)}\n`;
516517
}
517518
else {
518519
text += `git clone ${summary.repo.url} --recurse-submodules\n`;
@@ -721,15 +722,15 @@ export async function getTscRepoResult(
721722
summary += `### ${makeMarkdownLink(projectUrl)}\n`;
722723

723724
for (const errorMessage of newlyReportedErrorMessages) {
724-
summary += ` - ${buildWithNewWhenOldFails ? "[NEW] " : ""}\`${errorMessage}\`\n`;
725+
summary += ` - ${buildWithNewWhenOldFails ? "[NEW] " : ""}${asMarkdownInlineCode(errorMessage)}\n`;
725726

726727
for (const error of newlyReportedErrorMessageMap.get(errorMessage)!) {
727728
summary += ` - ${error.fileUrl ? makeMarkdownLink(error.fileUrl) : "Project Scope"}${isComposite ? ` in ${makeMarkdownLink(error.projectUrl)}` : ``}\n`;
728729
}
729730
}
730731

731732
for (const errorMessage of newlyUnreportedErrorMessages) {
732-
summary += ` - ${buildWithNewWhenOldFails ? "[MISSING] " : ""}\`${errorMessage}\`\n`;
733+
summary += ` - ${buildWithNewWhenOldFails ? "[MISSING] " : ""}${asMarkdownInlineCode(errorMessage)}\n`;
733734

734735
for (const error of newlyUnreportedErrorMessageMap.get(errorMessage)!) {
735736
summary += ` - ${error.fileUrl ? makeMarkdownLink(error.fileUrl) : "Project Scope"}${isComposite ? ` in ${makeMarkdownLink(error.projectUrl)}` : ``}\n`;

src/postGithubComments.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path = require("path");
33
import { artifactFolderUrlPlaceholder, getArtifactsApiUrlPlaceholder, Metadata, metadataFileName, RepoStatus, resultFileNameSuffix } from "./main";
44
import git = require("./utils/gitUtils");
55
import pu = require("./utils/packageUtils");
6+
import { asMarkdownInlineCode } from "./utils/markdownUtils";
67

78
const { argv } = process;
89

@@ -76,7 +77,7 @@ const outputs = resultPaths.map(p =>
7677
.replaceAll(getArtifactsApiUrlPlaceholder, getArtifactsApi));
7778

7879
const suiteDescription = isTopReposRun ? `top ${repoCount} repos` : "user tests";
79-
let header = `@${userToTag} Here are the results of running the ${suiteDescription} with ${entrypoint} comparing \`${oldTscResolvedVersion}\` and \`${newTscResolvedVersion}\`:
80+
let header = `@${userToTag} Here are the results of running the ${suiteDescription} with ${entrypoint} comparing ${asMarkdownInlineCode(oldTscResolvedVersion ?? "old")} and ${asMarkdownInlineCode(newTscResolvedVersion ?? "new")}:
8081
8182
${summary.join("\n")}`;
8283

src/utils/markdownUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function asMarkdownInlineCode(s: string) {
2+
let backticks = "`";
3+
let space = "";
4+
while (s.includes(backticks)) {
5+
backticks += "`";
6+
space = " "
7+
}
8+
return `${backticks}${space}${s}${space}${backticks}`;
9+
}

0 commit comments

Comments
 (0)