2024-08-09 12:04:48 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview XML character escaper
|
|
|
|
* @author George Chung
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Public Interface
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the escaped value for a character
|
|
|
|
* @param {string} s string to examine
|
|
|
|
* @returns {string} severity level
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
module.exports = function(s) {
|
2024-08-21 06:34:30 +00:00
|
|
|
return (`${s}`).replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, c => { // eslint-disable-line no-control-regex -- Converting controls to entities
|
2024-08-09 12:04:48 +00:00
|
|
|
switch (c) {
|
|
|
|
case "<":
|
|
|
|
return "<";
|
|
|
|
case ">":
|
|
|
|
return ">";
|
|
|
|
case "&":
|
|
|
|
return "&";
|
|
|
|
case "\"":
|
|
|
|
return """;
|
|
|
|
case "'":
|
|
|
|
return "'";
|
|
|
|
default:
|
|
|
|
return `&#${c.charCodeAt(0)};`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|