Skip to content

Commit

Permalink
MDL-61224 core_role: prevent short name from exceeding 100 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Jan 16, 2018
1 parent c9236c6 commit f393faa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion admin/roles/classes/define_role_table_advanced.php
Expand Up @@ -100,6 +100,8 @@ public function read_submitted_permissions() {
$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))) {
Expand Down Expand Up @@ -476,7 +478,7 @@ protected function get_name_field($id) {
}

protected function get_shortname_field($id) {
return '<input type="text" id="' . $id . '" name="' . $id . '" maxlength="254" value="' . s($this->role->shortname) . '"' .
return '<input type="text" id="' . $id . '" name="' . $id . '" maxlength="100" value="' . s($this->role->shortname) . '"' .
' class="form-control"/>';
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/role.php
Expand Up @@ -216,6 +216,7 @@
$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';
Expand Down

0 comments on commit f393faa

Please sign in to comment.