Nodejs HTML Escape escape_html()

Here you can find the source of escape_html()

Method Source Code

String.prototype.escape_html = function(){
  var span = document.createElement('span');
  var txt =  document.createTextNode('');
  span.appendChild(txt);/*from  w w w  .java2  s.co m*/
  txt.data = this;
  return span.innerHTML;
};

Related

  1. escapeHTML()
    String.prototype.escapeHTML = function () {
        return ('' + this).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
    }; 
    
  2. escapeHtml()
    String.prototype.escapeHtml = function() {
            return this
              .replace(/&/g, '&amp;')
                .replace(/"/g,  '&quot;')
                  .replace(/'/g,  '&#039;')
                    .replace(/</g,  '&lt;')
                      .replace(/>/g,  '&gt;');
    };
    
  3. escapeHtml()
    var entityMap = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#39;',
        '/': '&#x2F;'
    };
    String.prototype.escapeHtml = function() {
    ...
    
  4. escapeHtml()
    String.prototype.escapeHtml = String.prototype.escapeHtml || (String.prototype.escapeHtml = function() {
      return this.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    });
    
  5. escape_html()
    String.prototype.escape_html = function() {
        return this.replace(/&/g, "&amp;")
                   .replace(/</g, "&lt;")
                   .replace(/>/g, "&gt;")
                   .replace(/"/g, "&quot;");
    
  6. escape_html()
    String.prototype.escape_html = function(){
      var span = document.createElement('span');
      var txt =  document.createTextNode('');
      span.appendChild(txt);
      txt.data = this;
      return span.innerHTML;
    };
    var Notifer = new function(){
      var self = this;
    ...
    
  7. escapelHTML()
    String.prototype.escapelHTML = function(){
        return String(this)
            .replace(/&/g, "&amp;")
            .replace(/</g, "&lt;")
            .replace(/>/g, "&gt;")
            .replace(/"/g, "&quot;")
            .replace(/'/g, "&#039;")
            .replace(/\
    };
    ...
    
  8. htmlEscape()
    String.prototype.htmlEscape = function(){
        var span = document.createElement('span');
        var txt =  document.createTextNode('');
        span.appendChild(txt);
        txt.data = this;
        return span.innerHTML;
    };
    
  9. htmlEscape()
    String.prototype.htmlEscape = function () {
        return this.replace(/&/g, '%amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39');
    console.log('<script>'.htmlEscape());