|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import html_sanitizer from "./html_sanitizer.js"; |
| 3 | +import { trimIndentation } from "../../spec/support/utils.js"; |
| 4 | + |
| 5 | +describe("sanitize", () => { |
| 6 | + it("filters out position inline CSS", () => { |
| 7 | + const dirty = `<div style="z-index:999999999;margin:0px;left:250px;height:100px;display:table;background:none;position:fixed;top:250px;"></div>`; |
| 8 | + const clean = `<div></div>`; |
| 9 | + expect(html_sanitizer.sanitize(dirty)).toBe(clean); |
| 10 | + }); |
| 11 | + |
| 12 | + it("keeps inline styles defined in CKEDitor", () => { |
| 13 | + const dirty = trimIndentation`\ |
| 14 | + <p> |
| 15 | + <span style="color:hsl(0, 0%, 90%);"> |
| 16 | + Hi |
| 17 | + </span> |
| 18 | +
|
| 19 | + <span style="background-color:hsl(30, 75%, 60%);"> |
| 20 | + there |
| 21 | + </span> |
| 22 | + </p> |
| 23 | + <figure class="table" style="float:left;height:800px;width:600px;"> |
| 24 | + <table style="background-color:hsl(0, 0%, 90%);border-color:hsl(0, 0%, 0%);border-style:dotted;"> |
| 25 | + <tbody> |
| 26 | + <tr> |
| 27 | + <td style="border:2px groove hsl(60, 75%, 60%);"></td> |
| 28 | + </tr> |
| 29 | + </tbody> |
| 30 | + </table> |
| 31 | + </figure>`; |
| 32 | + const clean = trimIndentation`\ |
| 33 | + <p> |
| 34 | + <span style="color:hsl(0, 0%, 90%)"> |
| 35 | + Hi |
| 36 | + </span> |
| 37 | +
|
| 38 | + <span style="background-color:hsl(30, 75%, 60%)"> |
| 39 | + there |
| 40 | + </span> |
| 41 | + </p> |
| 42 | + <figure class="table" style="float:left;height:800px;width:600px"> |
| 43 | + <table style="background-color:hsl(0, 0%, 90%);border-color:hsl(0, 0%, 0%);border-style:dotted"> |
| 44 | + <tbody> |
| 45 | + <tr> |
| 46 | + <td style="border:2px groove hsl(60, 75%, 60%)"></td> |
| 47 | + </tr> |
| 48 | + </tbody> |
| 49 | + </table> |
| 50 | + </figure>`; |
| 51 | + expect(html_sanitizer.sanitize(dirty)) .toBe(clean); |
| 52 | + }); |
| 53 | +}); |
0 commit comments