all files / common/utils/ security.js

100% Statements 18/18
100% Branches 2/2
100% Functions 6/6
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44   8101×   8099×                                   240×                
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function sanitizeHelper(html, enableSanitizer) {
        if (!enableSanitizer) {
            return html;
        }
        return ej2_base_1.SanitizeHtmlHelper.sanitize(html);
    }
    exports.sanitizeHelper = sanitizeHelper;
    function decode(value) {
        var entityMap = {
            '&lt;': '<',
            '&gt;': '>',
            '&nbsp;': ' ',
            '&quot;': '"',
            '&#039;': '\'',
            '&apos;': '\'',
            '&amp;': '&'
        };
        return value.replace(/&(?:amp|lt|gt|nbsp|quot|#039|apos);/g, function (match) { return entityMap[match]; });
    }
    exports.decode = decode;
    function encode(value) {
        return value.trim()
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#039;')
            .replace(/\n/g, '<br>');
    }
    exports.encode = encode;
    function escapeHTML(text) {
        return text
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#039;');
    }
    exports.escapeHTML = escapeHTML;
});