Something went wrong. Try again.
I will pick a better name later.
Something went wrong. Try again.
1234567891011121314151617181920import { describe, expect, it } from "vitest";import { sanitizeArticleHtml } from "~/lib/article-sanitize";
describe("sanitizeArticleHtml", () => { it("removes scripts and unsafe event handlers", () => { const html = sanitizeArticleHtml('<article><h1>Title</h1><script>alert(1)</script><p onclick="bad()">Hello</p></article>'); expect(html).toContain("Title"); expect(html).toContain("Hello"); expect(html).not.toContain("script"); expect(html).not.toContain("onclick"); });
it("keeps safe article links and adds reader-safe link attributes", () => { const html = sanitizeArticleHtml('<p><a href="https://example.com">source</a></p>'); expect(html).toContain('href="https://example.com"'); expect(html).toContain('rel="noreferrer"'); expect(html).toContain('target="_blank"'); });});