Changed call from preg_replace() to preg_replace_callback() to avoid
some double backslashes present yet. This method doesn't addslashes() automatically like the old one (so kses_stripslashes() is not needed). All we have to to is to stripslashes() before calling kses and addslashes() after it. Only in clean_param(), because params arrive always slashed to Moodle. This seems to be the correct approach documented in: http://sourceforge.net/project/shownotes.php?group_id=81853&release_id=302996
This commit is contained in:
+2
-3
@@ -193,10 +193,9 @@ function clean_param($param, $options) {
|
||||
}
|
||||
|
||||
if ($options & PARAM_CLEAN) {
|
||||
$param = stripslashes($param);
|
||||
$param = clean_text($param); // Sweep for scripts, etc
|
||||
$param = str_replace('"', '\\\\"', $param); // Because clean_text will strip them
|
||||
// when checking HTML tags ... I'm not
|
||||
// sure if this is really necessary to replace
|
||||
$param = addslashes($param);
|
||||
}
|
||||
|
||||
if ($options & PARAM_INT) {
|
||||
|
||||
+7
-6
@@ -1247,9 +1247,9 @@ function clean_text($text, $format=FORMAT_MOODLE) {
|
||||
* @return string
|
||||
*/
|
||||
function cleanAttributes($str){
|
||||
$result = preg_replace(
|
||||
'%(<[^>]*(>|$)|>)%me', #search for html tags
|
||||
"cleanAttributes2('\\1')",
|
||||
$result = preg_replace_callback(
|
||||
'%(<[^>]*(>|$)|>)%m', #search for html tags
|
||||
"cleanAttributes2",
|
||||
$str
|
||||
);
|
||||
return $result;
|
||||
@@ -1261,15 +1261,16 @@ function cleanAttributes($str){
|
||||
* It calls ancillary functions in kses which are prefixed by kses
|
||||
* 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie
|
||||
*
|
||||
* @param string $htmlTag An html tag to be examined
|
||||
* @param array $htmlArray An array from {@link cleanAttributes()}, containing in its 1st
|
||||
* element the html to be cleared
|
||||
* @return string
|
||||
*/
|
||||
function cleanAttributes2($htmlTag){
|
||||
function cleanAttributes2($htmlArray){
|
||||
|
||||
global $CFG, $ALLOWED_PROTOCOLS;
|
||||
require_once($CFG->libdir .'/kses.php');
|
||||
|
||||
$htmlTag = str_replace('\\\\"', '"', $htmlTag);
|
||||
$htmlTag = $htmlArray[1];
|
||||
if (substr($htmlTag, 0, 1) != '<') {
|
||||
return '>'; //a single character ">" detected
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user