Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

appLinks.test.ts

32 lines1010 Bytes

1import { describe, expect, it } from "vite-plus/test";
2​
3import { appLinkUrl } from "./appLinks.ts";
4​
5describe("appLinkUrl", () => {
6 it("accepts schemes another app opens", () => {
7 expect(appLinkUrl("obsidian://open?vault=vault&file=Note")).toBe(
8 "obsidian://open?vault=vault&file=Note",
9 );
10 expect(appLinkUrl("t3-thread://v2/env/thread")).toBe("t3-thread://v2/env/thread");
11 expect(appLinkUrl("mailto:a@example.com")).toBe("mailto:a@example.com");
12 });
13​
14 it("rejects schemes the browser loads itself, and non-URLs", () => {
15 for (const url of [
16 "https://example.com",
17 "http://example.com",
18 "javascript:alert(1)",
19 "JavaScript:alert(1)",
20 "data:text/html,x",
21 "file:///etc/passwd",
22 "blob:https://example.com/id",
23 "about:blank",
24 "view-source:https://example.com",
25 "chrome://settings",
26 "filesystem:https://example.com/temporary/a",
27 "not a url",
28 ]) {
29 expect(appLinkUrl(url), url).toBeNull();
30 }
31 });
32});