feat(api): Allow disabled checkbox inputs in rich text

This commit is contained in:
Jesse Wierzbinski 2024-11-19 11:20:24 +01:00
parent 32f71b3adf
commit dc8a64355a
No known key found for this signature in database

View file

@ -79,6 +79,7 @@ export const sanitizeHtml = async (
audio: ["class", "src", "controls"], audio: ["class", "src", "controls"],
source: ["src", "type"], source: ["src", "type"],
track: ["src", "label", "kind"], track: ["src", "label", "kind"],
input: ["type", "checked", "disabled", "class"],
}, },
stripIgnoreTag: false, stripIgnoreTag: false,
escapeHtml: (unsafeHtml): string => escapeHtml: (unsafeHtml): string =>
@ -99,6 +100,7 @@ export const sanitizeHtml = async (
"hashtag", "hashtag",
"ellipsis", "ellipsis",
"invisible", "invisible",
"task-list-item-checkbox",
]; ];
return await new HTMLRewriter() return await new HTMLRewriter()
@ -117,6 +119,17 @@ export const sanitizeHtml = async (
} }
}, },
}) })
// Only allow disabled checkbox input
.on("input", {
element(element): void {
if (
element.getAttribute("type") === "checkbox" &&
element.getAttribute("disabled") === null
) {
element.removeAttribute("type");
}
},
})
.transform(new Response(sanitizedHtml)) .transform(new Response(sanitizedHtml))
.text(); .text();
}; };