import PrettyText, { buildOptions } from "pretty-text/pretty-text";
import { hrefAllowed } from "pretty-text/sanitizer";
QUnit.module("lib:sanitizer");
QUnit.test("sanitize", assert => {
const pt = new PrettyText(
buildOptions({
siteSettings: {
allowed_iframes:
"https://www.google.com/maps/embed?|https://www.openstreetmap.org/export/embed.html?"
}
})
);
const cooked = (input, expected, text) =>
assert.equal(pt.cook(input), expected.replace(/\/>/g, ">"), text);
assert.equal(pt.sanitize('bug'), "bug");
assert.equal(
pt.sanitize("
"),
""
);
assert.equal(
pt.sanitize(""),
""
);
assert.equal(pt.sanitize("<3 <3"), "<3 <3");
assert.equal(pt.sanitize("<_<"), "<_<");
cooked(
"hello",
"hello
",
"it sanitizes while cooking"
);
cooked(
"disney reddit",
'disney reddit
',
"we can embed proper links"
);
cooked("hello", "hello", "it does not allow centering");
cooked(
"a\n
\n",
"a\n
",
"it does not double sanitize"
);
cooked(
'',
"",
"it does not allow most iframes"
);
cooked(
'',
'',
"it allows iframe to google maps"
);
cooked(
'',
'',
"it allows iframe to OpenStreetMap"
);
assert.equal(pt.sanitize(""), "hullo");
assert.equal(pt.sanitize(""), "press me!");
assert.equal(pt.sanitize(""), "draw me!");
assert.equal(pt.sanitize("