feat: sanitize HTML in footer

moved sanitize function into a separate file including some simple tests

closes #91
This commit is contained in:
Danny Koppenhagen
2022-01-10 08:32:19 +01:00
committed by Bastian
parent 5a5928f2dd
commit e0113c446d
5 changed files with 45 additions and 17 deletions

20
src/sanitize.test.tsx Normal file
View File

@@ -0,0 +1,20 @@
import { sanitize } from "./sanitize";
describe("sanitize", () => {
it("should sanitize the string input to HTML output", () => {
let res = sanitize('foo');
expect(res.__html).toEqual("foo");
res = sanitize('<a href="https://example.org">Example.org</a>');
expect(res.__html).toEqual("<a href=\"https://example.org\">Example.org</a>");
});
it("should not sanitize not allowed tags", () => {
let res = sanitize('Before <iframe src="https://example.org"></iframe> After');
expect(res.__html).toEqual("Before After");
});
it("should accept options for rendering", () => {
let res = sanitize('<a href="https://example.org" target="_blank">Example.org</a>', { allowedAttributes: { a: ['href']}});
expect(res.__html).toEqual("<a href=\"https://example.org\">Example.org</a>");
});
});