Skip to content

Commit

Permalink
Validation for max allowed number of chars in custom groups name
Browse files Browse the repository at this point in the history
  • Loading branch information
pako81 committed Jan 7, 2020
1 parent c45853c commit b85ad48
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/GroupsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

// status 422 in case of validation error
if (response.status === 422) {
OC.Notification.showTemporary(t('customgroups', 'The group name can not be empty or start with space. The group name should at least have 2 characters. Or kindly check if a group with this name already exists'));
OC.Notification.showTemporary(t('customgroups', 'The group name can not be empty or start with space. The group name should at least have 2 characters or maximum 64 characters. Or kindly check if a group with this name already exists'));
return;
} else {
OC.Notification.showTemporary(t('customgroups', 'Could not rename group'));
Expand Down Expand Up @@ -269,7 +269,7 @@
return;
}
if (response.status === 422) {
OC.Notification.showTemporary(t('customgroups', "The group name can not be empty or start with space. The group name should at least have 2 characters"));
OC.Notification.showTemporary(t('customgroups', "The group name can not be empty or start with space. The group name should at least have 2 characters or maximum 64 characters"));
}
if (response.status === 403) {
OC.Notification.showTemporary(t('customgroups', 'Could not create group'));
Expand Down
5 changes: 5 additions & 0 deletions lib/Dav/GroupMembershipCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ public function updateDisplayName($displayName) {
throw new ValidationException("The group name should be at least 2 characters long.");
}

/* Verify if the multibyte character length is more than 64 */
if (\mb_strlen($displayName, 'UTF-8') > 64) {
throw new ValidationException('The group name should be maximum 64 characters long.');
}

if ($displayName[0] === ' ') {
throw new ValidationException('The group name can not start with space');
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Dav/GroupsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public function createExtendedCollection($name, Mkcol $mkCol) {
throw new ValidationException('The group name should be at least 2 characters long.');
}

/** Group name must be max 64 characters long */
if (\mb_strlen($name, 'UTF-8') > 64) {
throw new ValidationException('The group name should be maximum 64 characters long.');
}

/**
* A special case where index is appended with the group name
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/js/GroupsViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('GroupsView test', function() {
expect($groupEl.find('input').length).toEqual(0);

expect(notificationStub.calledOnce).toEqual(true);
expect(notificationStub.calledWith('The group name can not be empty or start with space. The group name should at least have 2 characters. Or kindly check if a group with this name already exists')).toEqual(true);
expect(notificationStub.calledWith('The group name can not be empty or start with space. The group name should at least have 2 characters or maximum 64 characters. Or kindly check if a group with this name already exists')).toEqual(true);

notificationStub.restore();
});
Expand Down

0 comments on commit b85ad48

Please sign in to comment.