Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
π Parse only autolinks from GFM, not the full extension set (#2648)
Luke Vella48449e237c9f
diff --git a/apps/web/src/features/poll/components/markdown-description.test.tsx b/apps/web/src/features/poll/components/markdown-description.test.tsxindex 8181d5635..9c7838688 100644--- a/apps/web/src/features/poll/components/markdown-description.test.tsx+++ b/apps/web/src/features/poll/components/markdown-description.test.tsx@@ -66,6 +66,22 @@ describe("MarkdownDescription", () => {expect(anchor?.getAttribute("href") ?? "").not.toContain("javascript:");});+ it("does not parse GFM structures the schema cannot preserve", () => {+ // Tables must not vanish into empty output β without table parsing the+ // source survives as plain text.+ const table = renderMarkdown("| a | b |\n|---|---|\n| 1 | 2 |");+ expect(table.querySelector("table")).toBeNull();+ expect(table.textContent).toContain("| a | b |");++ // Footnotes must not leave dangling in-page anchors. (Without footnote+ // parsing, [^1] falls back to a plain CommonMark reference link.)+ const footnote = renderMarkdown("text[^1]\n\n[^1]: note");+ expect(footnote.querySelector('a[href^="#"]')).toBeNull();++ // Strikethrough stays literal rather than silently losing its markup.+ expect(renderMarkdown("~~gone~~").textContent).toContain("~~gone~~");+ });+it("strips disallowed tags but keeps their text", () => {const container = renderMarkdown("# heading\n\n> quote\n\n`code`");expect(container.querySelector("h1")).toBeNull();diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex 0df2a0d62..1ba9dbb81 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -27,6 +27,8 @@"cmdk": "^1.1.1","input-otp": "^1.4.2","lucide-react": "^0.479.0",+ "mdast-util-gfm-autolink-literal": "^2.0.1",+ "micromark-extension-gfm-autolink-literal": "^2.1.0","next-themes": "^0.4.6","react": "19.2.6","react-aria-components": "^1.16.0",@@ -35,13 +37,13 @@"react-markdown": "^10.1.0","rehype-sanitize": "^6.0.0","remark-breaks": "^4.0.0",- "remark-gfm": "^4.0.1","sonner": "^2.0.6","tailwind-merge": "^1.12.0"},"devDependencies": {"@rallly/tsconfig": "workspace:*","@types/react": "19.2.13",- "@types/react-dom": "19.2.3"+ "@types/react-dom": "19.2.3",+ "unified": "^11.0.5"}}diff --git a/packages/ui/src/markdown-description.tsx b/packages/ui/src/markdown-description.tsxindex 51e7cbc82..9f30257b6 100644--- a/packages/ui/src/markdown-description.tsx+++ b/packages/ui/src/markdown-description.tsx@@ -1,10 +1,30 @@+import { gfmAutolinkLiteralFromMarkdown } from "mdast-util-gfm-autolink-literal";+import { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";import Markdown from "react-markdown";import type { Options as SanitizeSchema } from "rehype-sanitize";import rehypeSanitize from "rehype-sanitize";import remarkBreaks from "remark-breaks";-import remarkGfm from "remark-gfm";+import type { Plugin } from "unified";import { cn } from "./lib/utils";+// Autolink bare URLs only β the one GFM behavior we want. Using the full+// remark-gfm would also parse tables, strikethrough, task lists and footnotes,+// which the sanitize schema below can't preserve: tables collapse to empty+// output and footnotes leave dangling anchors. So we wire up just the autolink+// extension instead.+const remarkAutolinkLiteral: Plugin = function () {+ // These data fields are declared by remark-parse's type augmentation, which+ // we don't depend on directly β hence the local shape.+ const data = this.data() as {+ micromarkExtensions?: unknown[];+ fromMarkdownExtensions?: unknown[];+ };+ data.micromarkExtensions ??= [];+ data.micromarkExtensions.push(gfmAutolinkLiteral());+ data.fromMarkdownExtensions ??= [];+ data.fromMarkdownExtensions.push(gfmAutolinkLiteralFromMarkdown());+};+// Locked-down allowlist: only the formatting the editor can produce.// Deliberately built from scratch rather than extending rehype-sanitize's// defaultSchema so nothing (task lists, footnotes, images, headings, raw@@ -37,7 +57,7 @@ export function MarkdownDescription({)}><Markdown- remarkPlugins={[remarkGfm, remarkBreaks]}+ remarkPlugins={[remarkAutolinkLiteral, remarkBreaks]}rehypePlugins={[[rehypeSanitize, schema]]}components={{a: ({ href, children }) => (diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex be521bd1f..6a0ba62d1 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -785,6 +785,12 @@ importers:lucide-react:specifier: ^0.479.0version: 0.479.0([email protected])+ mdast-util-gfm-autolink-literal:+ specifier: ^2.0.1+ version: 2.0.1+ micromark-extension-gfm-autolink-literal:+ specifier: ^2.1.0+ version: 2.1.0next-themes:specifier: ^0.4.6@@ -809,9 +815,6 @@ importers:remark-breaks:specifier: ^4.0.0version: 4.0.0- remark-gfm:- specifier: ^4.0.1- version: 4.0.1sonner:specifier: ^2.0.6@@ -828,6 +831,9 @@ importers:'@types/react-dom':specifier: 19.2.3version: 19.2.3(@types/[email protected])+ unified:+ specifier: ^11.0.5+ version: 11.0.5packages/utils:dependencies: