Chatwoot/app/javascript/shared/helpers/HTMLSanitizer.js
2022-05-16 11:29:05 +05:30

20 lines
434 B
JavaScript

export const escapeHtml = (unsafe = '') => {
return unsafe
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
};
export const afterSanitizeAttributes = currentNode => {
if ('target' in currentNode) {
currentNode.setAttribute('target', '_blank');
}
};
export const domPurifyConfig = {
hooks: {
afterSanitizeAttributes,
},
};