Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { resolveExternalWebLinkHref } from "./externalLinkContextMenu";
4
5describe("external chat link context menu", () => {
6 it.each([
7 [
8 "https://example.com/docs?topic=security#links",
9 "https://example.com/docs?topic=security#links",
10 ],
11 ["HTTP://EXAMPLE.COM", "http://example.com/"],
12 ["//example.com/path", "https://example.com/path"],
13 ])("resolves the safe external web-link href for %s as %s", (href, expected) => {
14 expect(resolveExternalWebLinkHref(href)).toBe(expected);
15 });
16
17 it.each([
18 "javascript:alert(document.domain)",
19 " \nJaVaScRiPt:alert(document.domain)",
20 "data:text/html,<script>alert(document.domain)</script>",
21 "file:///tmp/example.txt",
22 "mailto:hello@example.com",
23 "/relative/path",
24 "not a URL",
25 "",
26 ])("rejects unsafe external web-link href %s", (href) => {
27 expect(resolveExternalWebLinkHref(href)).toBeNull();
28 });
29});