escape chars function

This commit is contained in:
Simon Martín
2017-12-18 11:14:27 +01:00
parent e4ae3e235d
commit cb7fb97a13
@@ -189,3 +189,22 @@ function setErrorHeader(errors, statusCode, res) {
res.set('X-Tiler-Errors', JSON.stringify(errorsLog));
}
/**
* Remove problematic nested characters
* from object for logs RegEx
*
* @param {Object} object
*/
function stringifyForLogs(object) {
Object.keys(object).map(key => {
const value = object[key];
if (object instanceof Object) {
stringifyForLogs(value);
} else {
object[key] = object[key].replace(/[^a-zA-Z0-9]/g, ' ');
}
});
return JSON.stringify(object);
}