diff --git a/lib/utils.js b/lib/utils.js index 31abf638..9e2c1d0b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -53,6 +53,10 @@ var _ENCODE_HTML_RULES = { } , _MATCH_HTML = /[&<>\'"]/g; +function encode_char(c) { + return _ENCODE_HTML_RULES[c] || c; +}; + /** * Stringified version of constants used by {@link module:utils.escapeXML}. * @@ -70,7 +74,10 @@ var escapeFuncStr = + ' , \'"\': """\n' + ' , "\'": "'"\n' + ' }\n' -+ ' , _MATCH_HTML = /[&<>\'"]/g;\n'; ++ ' , _MATCH_HTML = /[&<>\'"]/g;\n' ++ 'function encode_char(c) {\n' ++ ' return _ENCODE_HTML_RULES[c] || c;\n' ++ '};\n'; /** * Escape characters reserved in XML. @@ -83,13 +90,12 @@ var escapeFuncStr = * @static * @private */ + exports.escapeXML = function (markup) { return markup == undefined ? '' : String(markup) - .replace(_MATCH_HTML, function(m) { - return _ENCODE_HTML_RULES[m] || m; - }); + .replace(_MATCH_HTML, encode_char); }; exports.escapeXML.toString = function () { return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr