@@ -213,4 +213,76 @@ describe("documentImporter", () => {
|
|||||||
|
|
||||||
expect(error).toEqual("File type executable/zip not supported");
|
expect(error).toEqual("File type executable/zip not supported");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should escape dollar signs in HTML input", async () => {
|
||||||
|
const user = await buildUser();
|
||||||
|
const fileName = "test.html";
|
||||||
|
const content = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>$100</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
const response = await documentImporter({
|
||||||
|
user,
|
||||||
|
mimeType: "text/html",
|
||||||
|
fileName,
|
||||||
|
content,
|
||||||
|
ip,
|
||||||
|
});
|
||||||
|
expect(response.text).toEqual("\\$100");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not escape dollar signs in inline code in HTML input", async () => {
|
||||||
|
const user = await buildUser();
|
||||||
|
const fileName = "test.html";
|
||||||
|
const content = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<code>echo $foo</code>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
const response = await documentImporter({
|
||||||
|
user,
|
||||||
|
mimeType: "text/html",
|
||||||
|
fileName,
|
||||||
|
content,
|
||||||
|
ip,
|
||||||
|
});
|
||||||
|
expect(response.text).toEqual("`echo $foo`");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not escape dollar signs in code blocks in HTML input", async () => {
|
||||||
|
const user = await buildUser();
|
||||||
|
const fileName = "test.html";
|
||||||
|
const content = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<pre><code>echo $foo</code></pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
const response = await documentImporter({
|
||||||
|
user,
|
||||||
|
mimeType: "text/html",
|
||||||
|
fileName,
|
||||||
|
content,
|
||||||
|
ip,
|
||||||
|
});
|
||||||
|
expect(response.text).toEqual("```\necho $foo\n```");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,10 +63,6 @@ async function documentImporter({
|
|||||||
// to match our hardbreak parser.
|
// to match our hardbreak parser.
|
||||||
text = text.trim().replace(/<br>/gi, "\\n");
|
text = text.trim().replace(/<br>/gi, "\\n");
|
||||||
|
|
||||||
// Escape any dollar signs in the text to prevent them being interpreted as
|
|
||||||
// math blocks
|
|
||||||
text = text.replace(/\$/g, "\\$");
|
|
||||||
|
|
||||||
// Remove any closed and immediately reopened formatting marks
|
// Remove any closed and immediately reopened formatting marks
|
||||||
text = text.replace(/\*\*\*\*/gi, "").replace(/____/gi, "");
|
text = text.replace(/\*\*\*\*/gi, "").replace(/____/gi, "");
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ const escapes: [RegExp, string][] = [
|
|||||||
[/^>/g, "\\>"],
|
[/^>/g, "\\>"],
|
||||||
[/_/g, "\\_"],
|
[/_/g, "\\_"],
|
||||||
[/^(\d+)\. /g, "$1\\. "],
|
[/^(\d+)\. /g, "$1\\. "],
|
||||||
|
[/\$/g, "\\$"],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user