MCPcopy Index your code
hub / github.com/textAngular/textAngular / encodeEntities

Function encodeEntities

src/textAngular-sanitize.js:466–494  ·  view source on GitHub ↗

* Escapes all potentially dangerous characters, so that the * resulting string can be safely inserted into attribute or * element text. * @param value * @returns {string} escaped text

(value)

Source from the content-addressed store, hash-verified

464 * @returns {string} escaped text
465 */
466function encodeEntities(value) {
467 return value.
468 replace(/&/g, '&').
469 replace(SURROGATE_PAIR_REGEXP, function(value) {
470 var hi = value.charCodeAt(0);
471 var low = value.charCodeAt(1);
472 return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
473 }).
474 replace(NON_ALPHANUMERIC_REGEXP, function(value) {
475 // unsafe chars are: \u0000-\u001f \u007f-\u009f \u00ad \u0600-\u0604 \u070f \u17b4 \u17b5 \u200c-\u200f \u2028-\u202f \u2060-\u206f \ufeff \ufff0-\uffff from jslint.com/lint.html
476 // decimal values are: 0-31, 127-159, 173, 1536-1540, 1807, 6068, 6069, 8204-8207, 8232-8239, 8288-8303, 65279, 65520-65535
477 var c = value.charCodeAt(0);
478 // if unsafe character encode
479 if(c <= 159 ||
480 c == 173 ||
481 (c >= 1536 && c <= 1540) ||
482 c == 1807 ||
483 c == 6068 ||
484 c == 6069 ||
485 (c >= 8204 && c <= 8207) ||
486 (c >= 8232 && c <= 8239) ||
487 (c >= 8288 && c <= 8303) ||
488 c == 65279 ||
489 (c >= 65520 && c <= 65535)) return '&#' + c + ';';
490 return value; // avoids multilingual issues
491 }).
492 replace(/</g, '&lt;').
493 replace(/>/g, '&gt;');
494}
495
496var trim = (function() {
497 // native trim is way faster: http://jsperf.com/angular-trim-test

Callers 1

htmlSanitizeWriterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected