import { describe, expect, it } from "vitest"; import { safeReturn } from "@/lib/safe-return"; describe("safeReturn", () => { it("keeps internal paths with their query string", () => { expect(safeReturn("/operations?m=2026-10&q=a", "/")).toBe("/operations?m=2026-10&q=a"); expect(safeReturn("/", "/x")).toBe("/"); }); it("falls back for anything that could leave the site", () => { for (const bad of [undefined, "", "https://evil.com", "//evil.com", "/\\evil.com", "/%09/evil.com", "\t//evil.com", "javascript:alert(1)", "/\t/evil.com"]) { expect(safeReturn(bad, "/fallback")).toBe("/fallback"); } }); });