import "jest"; import { safeUrl } from "../safeUrl"; describe(safeUrl.name, () => { function test(input: string, expected: string) { expect(safeUrl(input)).toBe(expected); } it("preserves https:", () => test("https://google.com", "https://google.com")); it("preserves http:", () => test("http://google.com", "http://google.com")); it("preserves mailto:", () => test("mailto:john@example.com", "mailto:john@example.com")); it("preserves scheme relative", () => test("//example.com", "//example.com")); it("preserves absolute path", () => test("/projects/00000000-0000-0000-000000000000", "/projects/00000000-0000-0000-000000000000")); describe("prepend http://", () => { it("javascript: attack", () => test("javascript:alert(0)", "http://javascript:alert(0)")); it("relative path", () => test("foo/bar", "http://foo/bar")); it("example.com", () => test("example.com", "http://example.com")); }); });