caldav-adapter
Version:
CalDAV server for Node.js and Koa. Modernized and maintained for Forward Email.
25 lines (21 loc) • 627 B
JavaScript
/**
* Shared XML entity encoding utility
* Centralizes the XML encoding logic to avoid duplication across handlers.
*/
/**
* Encode special characters for XML content to prevent parsing errors
* @param {string} str - String to encode
* @returns {string} - XML-safe encoded string
*/
function encodeXMLEntities(str) {
if (typeof str !== 'string') {
return str;
}
return str
.replaceAll('&', '&') // Must be first to avoid double-encoding
.replaceAll('<', '<')
.replaceAll('>', '>')
.replaceAll('"', '"')
.replaceAll("'", ''');
}
module.exports = { encodeXMLEntities };