mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-26 01:41:04 +08:00
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.
20 lines
829 B
JavaScript
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);
|
|
});
|