Nodejs String Escape escapeSecure()

Here you can find the source of escapeSecure()

Method Source Code

/*/*w  w  w .j a va  2 s. co  m*/
 * Copyright 2015 Centreon (http://www.centreon.com/)
 * 
 * Centreon is a full-fledged industry-strength solution that meets 
 * the needs in IT infrastructure and application monitoring for 
 * service performance.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0  
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * For more information : contact@centreon.com
 * 
 */

/**
 * Escape a string for present javascript injection
 */
String.prototype.escapeSecure = function () {
  var returnStr, tmpStr;
  /* Remove script tags */
  tmpStr = $(this);
  tmpStr.find("script").remove();
  returnStr = tmpStr.html();

  return returnStr;
};

Related

  1. escapeSpecialChars()
    String.prototype.escapeSpecialChars = function () {
      return this.replace(/\\n/g, '\\\\n')
      .replace(/\\'/g, '\\\'')
      .replace(/\\'/g, '\\\'')
      .replace(/\\&/g, '\\\&')
      .replace(/\\r/g, '\\\r')
      .replace(/\\t/g, '\\\\t')
      .replace(/\\b/g, '\\\b')
      .replace(/\\f/g, '\\\f');
    ...
    
  2. escapeCharacters(chars)
    String.prototype.escapeCharacters = function(chars) {
        var foundChar = false;
        var length = chars.length;
        for (var i = 0; i < length; ++i) {
            if (this.indexOf(chars.charAt(i)) !== -1) {
                foundChar = true;
                break;
        if (!foundChar)
            return this;
        var result = "";
        for (var j = 0; j < this.length; ++j) {
            if (chars.indexOf(this.charAt(j)) !== -1)
                result += "\\";
            result += this.charAt(j);
        return result;
    };
    
  3. escapeForRegExp()
    String.prototype.escapeForRegExp = function() {
        return this.escapeCharacters("^[]{}()\\.$*+?|");
    };
    
  4. escapeOnce()
    String.prototype.escapeOnce = function () {
      return this.replace(/"/g, '&quot;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/&(?!([a-zA-Z]+|#\d+);)/g, '&amp;');
    };
    
  5. escapeQuotes()
    String.prototype.escapeQuotes = function()
      var m = {"\"": "\\\"", "'": "\\'"};
      return String(this.replace("\\", "\\\\")).replace(/["']/g, function(s)
        return m[s];
      });
    
  6. escapeSelector( find )
    String.prototype.escapeSelector = function( find )
      find = new RegExp( '([' + (find || '\[\]:') + '])' );
      return this.replace(find, '\\$1');
    };
    Array.prototype.powerSet = function()
      var i = 1,
          j = 0,
    ...
    
  7. escapeURL()
    String.prototype.escapeURL = function() {
      return escape(this)
    
  8. escaped()
    String.prototype.escaped = function () {
      return this.replace(/&/gim, "&amp;").replace(/</gim, "&lt;").replace(/>/gim, "&gt;").replace(/"/gim, "&quot;").replace(/'/gim, "&#39;");