recxmltorecjson
Version:
Converts recxml to recjson
41 lines (36 loc) • 823 B
JavaScript
/**
* Simple sanitization. It is not intended to sanitize
* malicious element values.
*
* character | escaped
* < <
* > >
* ( (
* ) )
* # #
* & &
* " "
* ' '
*/
var chars = {
'&': '&',
'#': '#',
'<': '<',
'>': '>',
'(': '(',
')': ')',
'"': '"',
"'": '''
};
function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
exports.sanitize = function sanitize(value) {
if (typeof value !== 'string') {
return value;
}
Object.keys(chars).forEach(function(key) {
value = value.replace(new RegExp(escapeRegExp(key), 'g'), chars[key]);
});
return value;
}