diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fb26c16ad80..04e066cc49b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -844,7 +844,7 @@ function clean_param($param, $type) { case PARAM_RAW_TRIMMED: // No cleaning, but strip leading and trailing whitespace. - $param = fix_utf8($param); + $param = (string)fix_utf8($param); return trim($param); case PARAM_CLEAN: @@ -859,7 +859,7 @@ function clean_param($param, $type) { case PARAM_CLEANHTML: // Clean html fragment. - $param = fix_utf8($param); + $param = (string)fix_utf8($param); // Sweep for scripts, etc. $param = clean_text($param, FORMAT_HTML); return trim($param); @@ -878,27 +878,27 @@ function clean_param($param, $type) { case PARAM_ALPHA: // Remove everything not `a-z`. - return preg_replace('/[^a-zA-Z]/i', '', $param); + return preg_replace('/[^a-zA-Z]/i', '', (string)$param); case PARAM_ALPHAEXT: // Remove everything not `a-zA-Z_-` (originally allowed "/" too). - return preg_replace('/[^a-zA-Z_-]/i', '', $param); + return preg_replace('/[^a-zA-Z_-]/i', '', (string)$param); case PARAM_ALPHANUM: // Remove everything not `a-zA-Z0-9`. - return preg_replace('/[^A-Za-z0-9]/i', '', $param); + return preg_replace('/[^A-Za-z0-9]/i', '', (string)$param); case PARAM_ALPHANUMEXT: // Remove everything not `a-zA-Z0-9_-`. - return preg_replace('/[^A-Za-z0-9_-]/i', '', $param); + return preg_replace('/[^A-Za-z0-9_-]/i', '', (string)$param); case PARAM_SEQUENCE: // Remove everything not `0-9,`. - return preg_replace('/[^0-9,]/i', '', $param); + return preg_replace('/[^0-9,]/i', '', (string)$param); case PARAM_BOOL: // Convert to 1 or 0. - $tempstr = strtolower($param); + $tempstr = strtolower((string)$param); if ($tempstr === 'on' or $tempstr === 'yes' or $tempstr === 'true') { $param = 1; } else if ($tempstr === 'off' or $tempstr === 'no' or $tempstr === 'false') { @@ -911,7 +911,7 @@ function clean_param($param, $type) { case PARAM_NOTAGS: // Strip all tags. $param = fix_utf8($param); - return strip_tags($param); + return strip_tags((string)$param); case PARAM_TEXT: // Leave only tags needed for multilang. @@ -919,7 +919,7 @@ function clean_param($param, $type) { // If the multilang syntax is not correct we strip all tags because it would break xhtml strict which is required // for accessibility standards please note this cleaning does not strip unbalanced '>' for BC compatibility reasons. do { - if (strpos($param, '') !== false) { + if (strpos((string)$param, '') !== false) { // Old and future mutilang syntax. $param = strip_tags($param, ''); if (!preg_match_all('/<.*>/suU', $param, $matches)) { @@ -946,7 +946,7 @@ function clean_param($param, $type) { } return $param; - } else if (strpos($param, '') !== false) { + } else if (strpos((string)$param, '') !== false) { // Current problematic multilang syntax. $param = strip_tags($param, ''); if (!preg_match_all('/<.*>/suU', $param, $matches)) { @@ -975,11 +975,12 @@ function clean_param($param, $type) { } } while (false); // Easy, just strip all tags, if we ever want to fix orphaned '&' we have to do that in format_string(). - return strip_tags($param); + return strip_tags((string)$param); case PARAM_COMPONENT: // We do not want any guessing here, either the name is correct or not // please note only normalised component names are accepted. + $param = (string)$param; if (!preg_match('/^[a-z][a-z0-9]*(_[a-z][a-z0-9_]*)?[a-z0-9]+$/', $param)) { return ''; } @@ -1004,15 +1005,15 @@ function clean_param($param, $type) { case PARAM_SAFEDIR: // Remove everything not a-zA-Z0-9_- . - return preg_replace('/[^a-zA-Z0-9_-]/i', '', $param); + return preg_replace('/[^a-zA-Z0-9_-]/i', '', (string)$param); case PARAM_SAFEPATH: // Remove everything not a-zA-Z0-9/_- . - return preg_replace('/[^a-zA-Z0-9\/_-]/i', '', $param); + return preg_replace('/[^a-zA-Z0-9\/_-]/i', '', (string)$param); case PARAM_FILE: // Strip all suspicious characters from filename. - $param = fix_utf8($param); + $param = (string)fix_utf8($param); $param = preg_replace('~[[:cntrl:]]|[&<>"`\|\':\\\\/]~u', '', $param); if ($param === '.' || $param === '..') { $param = ''; @@ -1021,7 +1022,7 @@ function clean_param($param, $type) { case PARAM_PATH: // Strip all suspicious characters from file path. - $param = fix_utf8($param); + $param = (string)fix_utf8($param); $param = str_replace('\\', '/', $param); // Explode the path and clean each element using the PARAM_FILE rules. @@ -1043,7 +1044,7 @@ function clean_param($param, $type) { case PARAM_HOST: // Allow FQDN or IPv4 dotted quad. - $param = preg_replace('/[^\.\d\w-]/', '', $param ); + $param = preg_replace('/[^\.\d\w-]/', '', (string)$param ); // Match ipv4 dotted quad. if (preg_match('/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/', $param, $match)) { // Confirm values are ok. @@ -1067,7 +1068,7 @@ function clean_param($param, $type) { case PARAM_URL: // Allow safe urls. - $param = fix_utf8($param); + $param = (string)fix_utf8($param); include_once($CFG->dirroot . '/lib/validateurlsyntax.php'); if (!empty($param) && validateUrlSyntax($param, 's?H?S?F?E-u-P-a?I?p?f?q?r?')) { // All is ok, param is respected. @@ -1100,7 +1101,7 @@ function clean_param($param, $type) { return $param; case PARAM_PEM: - $param = trim($param); + $param = trim((string)$param); // PEM formatted strings may contain letters/numbers and the symbols: // forward slash: / // plus sign: + @@ -1148,7 +1149,7 @@ function clean_param($param, $type) { } case PARAM_TAG: - $param = fix_utf8($param); + $param = (string)fix_utf8($param); // Please note it is not safe to use the tag name directly anywhere, // it must be processed with s(), urlencode() before embedding anywhere. // Remove some nasties. @@ -1159,7 +1160,7 @@ function clean_param($param, $type) { return $param; case PARAM_TAGLIST: - $param = fix_utf8($param); + $param = (string)fix_utf8($param); $tags = explode(',', $param); $result = array(); foreach ($tags as $tag) { @@ -1222,7 +1223,7 @@ function clean_param($param, $type) { } case PARAM_USERNAME: - $param = fix_utf8($param); + $param = (string)fix_utf8($param); $param = trim($param); // Convert uppercase to lowercase MDL-16919. $param = core_text::strtolower($param); @@ -1236,14 +1237,14 @@ function clean_param($param, $type) { case PARAM_EMAIL: $param = fix_utf8($param); - if (validate_email($param)) { + if (validate_email($param ?? '')) { return $param; } else { return ''; } case PARAM_STRINGID: - if (preg_match('|^[a-zA-Z][a-zA-Z0-9\.:/_-]*$|', $param)) { + if (preg_match('|^[a-zA-Z][a-zA-Z0-9\.:/_-]*$|', (string)$param)) { return $param; } else { return ''; @@ -1251,7 +1252,7 @@ function clean_param($param, $type) { case PARAM_TIMEZONE: // Can be int, float(with .5 or .0) or string seperated by '/' and can have '-_'. - $param = fix_utf8($param); + $param = (string)fix_utf8($param); $timezonepattern = '/^(([+-]?(0?[0-9](\.[5|0])?|1[0-3](\.0)?|1[0-2]\.5))|(99)|[[:alnum:]]+(\/?[[:alpha:]_-])+)$/'; if (preg_match($timezonepattern, $param)) { return $param; @@ -1390,7 +1391,7 @@ function get_host_from_url($url) { * images, objects, etc. */ function html_is_blank($string) { - return trim(strip_tags($string, '