Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: escape residual markup in email catalogue excerpts

Richie McIlroy103d997853c1
diff --git a/scripts/emails/catalog.test.ts b/scripts/emails/catalog.test.ts
index f7155cd4c..fc56bb276 100644
--- a/scripts/emails/catalog.test.ts
+++ b/scripts/emails/catalog.test.ts
@@ -3,6 +3,7 @@ import { components, emailContent } from "../../emails/brand";
import { journeys } from "../../emails/flows";
import { freeWelcome } from "../../emails/marketing/free-welcome";
import {
+ catalogExcerpt,
flowSteps,
renderCatalog,
validateCatalog,
@@ -12,6 +13,14 @@ import {
import { assertEmailContent, normalizeLmx } from "./content";
describe("email library", () => {
+ test("catalogue excerpts keep malformed markup inert", () => {
+ expect(catalogExcerpt("<Paragraph>Hello</Paragraph><script src=x")).toBe(
+ "Hello\n\n&lt;script src=x",
+ );
+ expect(
+ catalogExcerpt("<Paragraph>Record & share<Br />Next step</Paragraph>"),
+ ).toBe("Record &amp; share\nNext step");
+ });
test("every template and known application send source is registered", async () => {
expect(await validateCatalog()).toEqual([]);
});
diff --git a/scripts/emails/catalog.ts b/scripts/emails/catalog.ts
index a67d8365d..27cce50ca 100644
--- a/scripts/emails/catalog.ts
+++ b/scripts/emails/catalog.ts
@@ -178,6 +178,16 @@ const resourceIds: Record<string, string> = resources.resources;
const flowUrl = (key: string) =>
`https://app.loops.so/workflows/${resourceIds[key]}`;
+export const catalogExcerpt = (body: string) =>
+ body
+ .replace(/<\/(Paragraph|Button)>/g, "\n\n")
+ .replace(/<Br\s*\/>/g, "\n")
+ .replace(/<[^>]+>/g, "")
+ .replaceAll("&", "&amp;")
+ .replaceAll("<", "&lt;")
+ .replaceAll(">", "&gt;")
+ .trim();
+
export const renderCatalog = () => {
const lines = [
"# Cap email catalogue",
@@ -306,12 +316,7 @@ export const renderCatalog = () => {
"",
`**Edit:** ${sourceLink(sourceFor(email))}`,
"",
- ...email.body
- .replace(/<\/(Paragraph|Button)>/g, "\n\n")
- .replace(/<Br\s*\/>/g, "\n")
- .replace(/<[^>]+>/g, "")
- .trim()
- .split("\n"),
+ ...catalogExcerpt(email.body).split("\n"),
"",
);
}