mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-25 06:40:30 +08:00
30 lines
843 B
TypeScript
30 lines
843 B
TypeScript
import { describe, expect, test } from "vitest";
|
|
|
|
import { safeHttpUrl } from "@app/lib/utils";
|
|
|
|
describe("safeHttpUrl", () => {
|
|
test.each([
|
|
["http://example.com/", "http://example.com/"],
|
|
["https://example.com/path?a=1&b=2", "https://example.com/path?a=1&b=2"],
|
|
["HTTP://EXAMPLE.com/Path", "http://example.com/Path"],
|
|
["http://example.com/<script>", "http://example.com/%3Cscript%3E"],
|
|
])("accepts %p", (input, expected) => {
|
|
expect(safeHttpUrl(input)).toBe(expected);
|
|
});
|
|
|
|
test.each([
|
|
"javascript:alert(1)",
|
|
"\tjavascript:alert(1)",
|
|
"data:text/html,<script>alert(1)</script>",
|
|
"vbscript:msgbox(1)",
|
|
"file:///etc/passwd",
|
|
"//example.com",
|
|
"/relative/path",
|
|
"relative",
|
|
"",
|
|
"not a url",
|
|
])("rejects %p", input => {
|
|
expect(safeHttpUrl(input)).toBeUndefined();
|
|
});
|
|
});
|