Sanitize Globals

This function does the following:

Unsets $_GET data (if query strings are not enabled)

Unsets all globals if register_globals is enabled

Standardizes newline characters to \n

@access private
@return void
771845
private function sanitizeGlobals() {
		// It would be "wrong" to unset any of these GLOBALS.
		$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN');
		
		// Unset globals for securiy.
		// This is effectively the same as register_globals = off
		foreach (array($_GET, $_POST, $_COOKIE) as $global) {
			if (!is_array($global)) {
				if (!in_array($global, $protected)) {
					global $$global;
					$$global = NULL;
				}
			} else {
				foreach ($global as $key => $val) {
					if (!in_array($key, $protected)) {
						global $$key;
						$$key = NULL;
					}
				}
			}
		}
		
		// Is $_GET data allowed? If not we'll set the $_GET to an empty array
		if (is_array($_GET) and count($_GET) > 0) {
			foreach ($_GET as $key => $val) {
				$_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
			}
		}
		
		// Clean $_POST Data
		if (is_array($_POST) and count($_POST) > 0) {
			foreach ($_POST as $key => $val) {
				$_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
			}
		}
		
		// Clean $_COOKIE Data
		if (is_array($_COOKIE) and count($_COOKIE) > 0) {
			// Also get rid of specially treated cookies that might be set by a
			// server
			// or silly application, that are of no use to a CI application
			// anyway
			// but that when present will trip our 'Disallowed Key Characters'
			// alarm
			// http://www.ietf.org/rfc/rfc2109.txt
			// note that the key names below are single quoted strings, and are
			// not PHP variables
			unset($_COOKIE['$Version']);
			unset($_COOKIE['$Path']);
			unset($_COOKIE['$Domain']);
			
			foreach ($_COOKIE as $key => $val) {
				$_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
			}
		}
		
		// Sanitize PHP_SELF
		$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
		
		// CSRF Protection check
		if ($this->_enable_csrf == TRUE) {
			Security::csrf_verify();
		}
		
	}
411282
private function removeConfigArrays()
    {
        $this->info("Removing the 'locales' and 'skip_locales' arrays from config/app.php");
        $this->helper->pregReplaceAndSave($this->config->paths->config->app, $this->regexLocalesString, $this->newLocalesString);
        $this->helper->pregReplaceAndSave($this->config->paths->config->app, $this->regexSkipLocalesString, $this->newSkipLocalesString);
        $this->bar->advance();
    }
1258844
public function sanitize($string, $max_length = 0, $allowed = '')
    {
        $text = trim(strip_tags($string, $allowed));
        if ($max_length > 0) {
            if (function_exists('mb_substr')) {
                $text = mb_substr($text, 0, $max_length, APP_CHARSET);
            } else {
                $text = substr($text, 0, $max_length);
            }
        }
        if ($text == null) {
            return ""; // we need to explicitly return a string otherwise some DB functions might insert this as a ZERO.
        }

        return $text;
    }
811824
public static function sanitize($string, $reverse = false)
    {
        $returnValue = (string) '';

        
		if ($reverse) {
			$smap = array('"', "\n", "\t", "\r");
			$rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r');
			$returnValue = (string) str_replace($smap, $rmap, $string);
		} else {
			$smap = array('/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\\"/');
			$rmap = array('', "\n", "\r", "\t", '"');
			$returnValue = (string) preg_replace($smap, $rmap, $string);
		}
        

        return (string) $returnValue;
    }
883387
def sanitize(text)
      text.gsub!(/[^a-z ]/i, '')
      text.gsub!(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/, '')
      text.gsub!(/(?=\w*h)(?=\w*t)(?=\w*t)(?=\w*p)\w*/, '')
      text.gsub!(/\s\s+/, ' ')

      text.downcase    
    end
378399
public function sanitize($value)
    {
        if (null === $this->_charList) {
            return trim((string) $value);
        } else {
            return trim((string) $value, $this->_charList);
        }
    }
871306
public function sanitize($input = false) {

        if($input) {

            if(Validate::isArray($input)) {

                return filter_var_array($input,FILTER_SANITIZE_STRING);
            } 
            if(Validate::isString($input)) {
                
                return filter_var($input, FILTER_SANITIZE_STRING);
            } 
        }

        return false;
    }
1000150
def sanitize(value):
    """"""

    value = unicodedata.normalize('NFKD', value)
    value = value.strip()
    value = re.sub('[^./\w\s-]', '', value)
    value = re.sub('[-\s]+', '-', value)

    return value
463981
protected function cleanVars(){
        $this->select= "*";
        $this->from= '';
        $this->where= '';
        $this->where_values= array();
        $this->group= '';
        $this->having= '';
        $this->order= '';
        $this->limit= '';
    }
211997
function _sanitize (chunk) {

  if (chunk && typeof chunk === 'object' && chunk.toString) {
    chunk = chunk.toString();
  }
  if (typeof chunk === 'string') {
    chunk = chunk.replace(/^[\s\n]*/, '');
    chunk = chunk.replace(/[\s\n]*$/, '');
  }
  return chunk;
}
1144840
protected function _sanitize($value)
    {
        $value = trim($value);

        $parts  = explode('-', $value, 2);
        if (2 != count($parts)) {
            return null;
        }

        $parts[0]   = substr(preg_replace('/[^a-z]*/', '', $parts[0]), 0, 2);
        $parts[1]   = substr(preg_replace('/[^A-Z]*/', '', $parts[1]), 0, 2);
        $result = implode('-', $parts);

        // just making sure :-)
        if ($this->_validate($result)) {
            return $result;
        }

        return null;
    }
270711
private function cleanup()
    {
        foreach ($this->tokens as $i => $t) {
            if ($t[0] === self::$deleteToken) {
                unset($this->tokens[$i]);
            }
        }
        $this->tokens = array_values($this->tokens);
    }
920559
function sanitiseString($string)
    {
        $search = array('–', '’');
        $replace = array('-', '\'');
        $string = str_replace($search, $replace, $string);
        return $string;
    }
1009394
function sanitize (val) {
  if (typeof val !== 'string') {
    return '';
  }
  val = val.replace(/\n/g,'\n');
  val = val.replace(/"/g,'""');
  return val ;
}
622346
private function unsetMagicConstants(): void
  {
    unset($this->replace['__FILE__']);
    unset($this->replace['__ROUTINE__']);
    unset($this->replace['__DIR__']);
    unset($this->replace['__LINE__']);
  }
200630
public function unserialize($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as $line) {
            $data = explode(':', $line);
            if (count($data) < 2) {
                continue;
            }
            $key = trim($data[0]);
            if (isset($data[1]) && (strlen($data[1]) > 0)) {
                $value = trim($data[1]);
            } else {
                $value = '?';
            }
            if (strcasecmp($key, 'set') === 0) {
                $data = explode('=', $value);
                $key = trim($data[0]);
                if (isset($data[1]) && (strlen($data[1]) > 0)) {
                    $value = trim($data[1]);
                } else {
                    $value = '?';
                }
                $this->setVariable($key, $value);
            } else {
                $this->setParameter($key, $value);
            }
        }
    }
456465
private function sanitize($value)
    {
        if ($value === null) {
            $value = 'null';
        }

        if (is_array($value)) {
            $value = 'array';
        }

        if (is_bool($value)) {
            $value = $value
                ? 'true'
                : 'false';
        }

        return $value;
    }