From fde9d39538073a43c726105cc96113f96d852144 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 16 Jan 2018 18:13:20 +0800 Subject: [PATCH] MDL-61224 core_role: prevent short name from exceeding 100 chars --- admin/roles/classes/define_role_table_advanced.php | 4 +++- lang/en/role.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/admin/roles/classes/define_role_table_advanced.php b/admin/roles/classes/define_role_table_advanced.php index bcf6a495d1f..19c9451ea57 100644 --- a/admin/roles/classes/define_role_table_advanced.php +++ b/admin/roles/classes/define_role_table_advanced.php @@ -100,6 +100,8 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi $this->role->shortname = core_text::strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT)); if (empty($this->role->shortname)) { $this->errors['shortname'] = get_string('errorbadroleshortname', 'core_role'); + } else if (core_text::strlen($this->role->shortname) > 100) { // Check if it exceeds the max of 100 characters. + $this->errors['shortname'] = get_string('errorroleshortnametoolong', 'core_role'); } } if ($DB->record_exists_select('role', 'shortname = ? and id <> ?', array($this->role->shortname, $this->roleid))) { @@ -476,7 +478,7 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi } protected function get_shortname_field($id) { - return ''; } diff --git a/lang/en/role.php b/lang/en/role.php index 14c7ac5427e..9ebf74dd259 100644 --- a/lang/en/role.php +++ b/lang/en/role.php @@ -213,6 +213,7 @@ $string['errorbadrolename'] = 'Incorrect role name'; $string['errorbadroleshortname'] = 'Incorrect role short name'; $string['errorexistsrolename'] = 'Role name already exists'; $string['errorexistsroleshortname'] = 'Role name already exists'; +$string['errorroleshortnametoolong'] = 'The short name must not exceed 100 characters'; $string['eventroleallowassignupdated'] = 'Allow role assignment'; $string['eventroleallowoverrideupdated'] = 'Allow role override'; $string['eventroleallowswitchupdated'] = 'Allow role switch';