Bug #5678 - Question marks, single quotes in field name cause trouble - cleaning hack ported from clean_filename(); merged from MOODLE_16_STABLE

This commit is contained in:
skodak
2006-06-06 10:17:18 +00:00
parent 9aafe70227
commit 002ccfc7a0
2 changed files with 10 additions and 4 deletions
+2 -4
View File
@@ -79,8 +79,7 @@
case 'add': ///add a new field
if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){
$fieldinput->name = clean_param($fieldinput->name, PARAM_NOTAGS);
$fieldinput->name = trim($fieldinput->name);
$fieldinput->name = data_clean_field_name($fieldinput->name);
/// Only store this new field if it doesn't already exist.
if (($fieldinput->name == '') or data_fieldname_exists($fieldinput->name, $data->id)) {
@@ -114,8 +113,7 @@
case 'update': ///update a field
if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){
$fieldinput->name = clean_param($fieldinput->name, PARAM_NOTAGS);
$fieldinput->name = trim($fieldinput->name);
$fieldinput->name = data_clean_field_name($fieldinput->name);
if (($fieldinput->name == '') or data_fieldname_exists($fieldinput->name, $data->id, $fieldinput->fid)) {
+8
View File
@@ -1239,5 +1239,13 @@ function data_convert_arrays_to_strings(&$fieldinput) {
}
}
function data_clean_field_name($fn) {
$fn = trim($fn);
//hack from clean_filename - to be replaced by something nicer later
$fn = preg_replace("/[\\000-\\x2c\\x2f\\x3a-\\x40\\x5b-\\x5e\\x60\\x7b-\\177]/s", '_', $fn);
$fn = preg_replace("/_+/", '_', $fn);
$fn = preg_replace("/\.\.+/", '.', $fn);
return $fn;
}
?>