Bug #5678 - Question marks, single quotes in field name cause trouble - cleaning hack ported from clean_filename()
This commit is contained in:
+2
-4
@@ -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)) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user