import { test } from "node:test"; import assert from "node:assert/strict"; import { urlToOutputPath } from "../src/utils/wayback-url.js"; test("urlToOutputPath preserves host and path layout", () => { assert.equal( urlToOutputPath( "https://example.com/wp-content/uploads/2020/01/photo.jpg", "/out", ), "/out/example.com/wp-content/uploads/2020/01/photo.jpg", ); }); test("urlToOutputPath decodes percent-encoded segments", () => { assert.equal( urlToOutputPath("https://example.com/uploads/foto%20test.jpg", "/out"), "/out/example.com/uploads/foto test.jpg", ); }); test("urlToOutputPath sanitizes path-traversal segments", () => { const out = urlToOutputPath("https://example.com/../etc/passwd", "/out"); assert.ok(!out.includes("..")); }); test("urlToOutputPath omits host directory when hostPrefix=false", () => { assert.equal( urlToOutputPath( "https://example.com/wp-content/uploads/2020/01/photo.jpg", "/out", { hostPrefix: false }, ), "/out/wp-content/uploads/2020/01/photo.jpg", ); }); test("urlToOutputPath falls back to 'index' for empty paths", () => { assert.equal( urlToOutputPath("https://example.com/", "/out"), "/out/example.com/index", ); });