Files
ARTEX/web/src/lib/http-href.test.mjs
T
Coff0xc d1431cfdcd fix(web): only http(s) asset URLs become service hrefs
The Services tab wrote the stored asset URL into href with no scheme
check. A javascript: or data: value stored via insert_assets or the
asset API became a clickable link. Non-http(s) URLs now render as text.
2026-11-18 22:39:38 +01:00

20 lines
829 B
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { httpHref } from "./http-href.ts";
test("httpHref allows http and https", () => {
assert.equal(httpHref("https://example.com/a"), "https://example.com/a");
assert.equal(httpHref("http://192.0.2.1:8080/x"), "http://192.0.2.1:8080/x");
assert.equal(httpHref(" https://example.com/a "), "https://example.com/a");
});
test("httpHref refuses javascript, data, and junk", () => {
assert.equal(httpHref("javascript:alert(1)"), undefined);
assert.equal(httpHref("JAVASCRIPT:alert(1)"), undefined);
assert.equal(httpHref("data:text/html,x"), undefined);
assert.equal(httpHref("vbscript:x"), undefined);
assert.equal(httpHref("/relative"), undefined);
assert.equal(httpHref(""), undefined);
assert.equal(httpHref(null), undefined);
});