2021-04-13 10:57:08 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
2021-06-18 20:41:54 +02:00
|
|
|
import { filterHTML } from ".";
|
|
|
|
|
|
|
|
describe("filterHTML", () => {
|
|
|
|
test("zero input creates zero output", () => {
|
|
|
|
expect(filterHTML("", true, false)).toBe("");
|
|
|
|
expect(filterHTML("", true, false)).toBe("");
|
|
|
|
expect(filterHTML("", false, false)).toBe("");
|
|
|
|
});
|
2022-08-19 04:31:26 +02:00
|
|
|
test("internal filtering", () => {
|
|
|
|
// font-size is filtered, weight is not
|
|
|
|
expect(
|
|
|
|
filterHTML(
|
2022-11-28 00:33:04 +01:00
|
|
|
"<div style=\"font-weight: bold; font-size: 10px;\"></div>",
|
2022-08-19 04:31:26 +02:00
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
2022-11-28 00:33:04 +01:00
|
|
|
).toBe("<div style=\"font-weight: bold;\"></div>");
|
2022-08-19 04:31:26 +02:00
|
|
|
});
|
|
|
|
test("background color", () => {
|
|
|
|
// transparent is stripped, other colors are not
|
|
|
|
expect(
|
|
|
|
filterHTML(
|
2022-11-28 00:33:04 +01:00
|
|
|
"<span style=\"background-color: transparent;\"></span>",
|
2022-08-19 04:31:26 +02:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
),
|
2022-11-28 00:33:04 +01:00
|
|
|
).toBe("<span style=\"\"></span>");
|
2022-08-19 04:31:26 +02:00
|
|
|
expect(
|
2022-11-28 00:33:04 +01:00
|
|
|
filterHTML("<span style=\"background-color: blue;\"></span>", false, true),
|
|
|
|
).toBe("<span style=\"background-color: blue;\"></span>");
|
2022-08-19 04:31:26 +02:00
|
|
|
// except if extended mode is off
|
|
|
|
expect(
|
2022-11-28 00:33:04 +01:00
|
|
|
filterHTML("<span style=\"background-color: blue;\">x</span>", false, false),
|
2022-08-19 04:31:26 +02:00
|
|
|
).toBe("x");
|
2022-10-24 01:24:48 +02:00
|
|
|
// no filtering on internal paste
|
2022-08-19 04:31:26 +02:00
|
|
|
expect(
|
2022-10-24 01:24:48 +02:00
|
|
|
filterHTML(
|
2022-11-28 00:33:04 +01:00
|
|
|
"<span style=\"background-color: transparent;\"></span>",
|
2022-10-24 01:24:48 +02:00
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
2022-11-28 00:33:04 +01:00
|
|
|
).toBe("<span style=\"background-color: transparent;\"></span>");
|
2022-08-19 04:31:26 +02:00
|
|
|
});
|
2021-03-28 11:39:11 +02:00
|
|
|
});
|