Skip to content
Snippets Groups Projects
Commit befb8f48 authored by Prasad's avatar Prasad
Browse files

Added vtlib helper method to remove quoted content in strings like strip_tags

parent 1c009a83
No related branches found
No related tags found
No related merge requests found
......@@ -733,6 +733,35 @@ function vtlib_purify($input, $ignore = false) {
return $value;
}
/**
* Remove content within quotes (single/double/unbalanced)
* Helpful to keep away quote-injection xss attacks in the templates.
*/
function vtlib_strip_quoted($input) {
$output = $input;
/*
* Discard anything in "double quoted until'you find next double quote"
* or discard anything in 'single quoted until "you" find next single quote"
*/
$qchar = '"';
$idx = strpos($input, $qchar);
if ($idx === false) { // no double-quote, find single-quote
$qchar = "'";
$idx = strpos($input, $qchar);
}
if ($idx !== false) {
$output = substr($input,0, $idx);
$idx = strpos($input, $qchar, $idx+1);
if ($idx === false) {
// unbalanced - eat all.
$idx = strlen($input)-1;
}
$input = substr($input, $idx+1);
$output .= vtlib_strip_quoted($input);
}
return $output;
}
/**
* Function to replace values in multi dimentional array (str_replace will support only one level of array)
* @param type $search
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment