audiobookshelf/server/libs/xml/escapeForXML.js

17 lines
325 B
JavaScript
Raw Normal View History

var XML_CHARACTER_MAP = {
'&': '&',
'"': '"',
"'": ''',
'<': '&lt;',
'>': '&gt;'
};
function escapeForXML(string) {
return string && string.replace
? string.replace(/([&"<>'])/g, function (str, item) {
return XML_CHARACTER_MAP[item];
})
: string;
}
module.exports = escapeForXML;