* malicious element values.
*
* character | escaped
* < <
* > >
* ( (
* ) )
* # #
* & &
* " "
* ' '
*/
var chars = { '<': '<',
'>': '>',
'(': '(',
')': ')',
'#': '#',
'&': '&',
'"': '"',
"'": ''' };
function sanitize(value) {
if (typeof value !== 'string') {
return value;
}
Object.keys(chars).forEach(function(key) {
value = value.replace(key, chars[key]);
});
return value;
}
/**
* Parses xml to json using node-expat.
* @param {String|Buffer} xml The xml to be parsed to json.
* @param {Object} _options An object with options provided by the user.
* The available options are:
* - object: If true, the parser returns a Javascript object instead of
* a JSON string.
* - reversible: If true, the parser generates a reversible JSON, mainly
* characterized by the presence of the property $t.
* - sanitize_values: If true, the parser escapes any element value in the xml
* that has any of the following characters: <, >, (, ), #, #, &, ", '.