Skip to content

Commit

Permalink
pkp/pkp-lib#9421 Handle edge case when number 0 was converted to empt…
Browse files Browse the repository at this point in the history
…y string by sanitize.
  • Loading branch information
jardakotesovec committed Jan 31, 2024
1 parent 416ac47 commit f6d7fa6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/directive/allowedHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ const sanitizeConfig = {
export const allowedHtmlDirective = {
beforeMount(el, binding) {
// Sanitize the content before inserting it into the element
const cleanContent = DOMPurify.sanitize(binding.value, sanitizeConfig);
const cleanContent = DOMPurify.sanitize(
String(binding.value),
sanitizeConfig,
);

el.innerHTML = cleanContent;
},
updated(el, binding) {
// Re-sanitize the content if the bound value changes
if (binding.value !== binding.oldValue) {
const cleanContent = DOMPurify.sanitize(binding.value, sanitizeConfig);
const cleanContent = DOMPurify.sanitize(
String(binding.value),
sanitizeConfig,
);
el.innerHTML = cleanContent;
}
},
Expand Down

0 comments on commit f6d7fa6

Please sign in to comment.