mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
Revert "feat(group): Sanitize group names and ids on creation"
This commit is contained in:
parent
6ba4ca3d8f
commit
f4b4cb5493
2 changed files with 3 additions and 26 deletions
|
|
@ -67,7 +67,6 @@ class Database extends ABackend implements
|
|||
public function createGroup(string $name): ?string {
|
||||
$this->fixDI();
|
||||
|
||||
$name = $this->sanitizeGroupName($name);
|
||||
$gid = $this->computeGid($name);
|
||||
try {
|
||||
// Add group
|
||||
|
|
@ -587,21 +586,12 @@ class Database extends ABackend implements
|
|||
return 'Database';
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge any white spaces to a single space in group name, then trim it.
|
||||
*/
|
||||
private function sanitizeGroupName(string $displayName): string {
|
||||
$cleanedDisplayName = preg_replace('/\s+/', ' ', $displayName);
|
||||
return trim($cleanedDisplayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute group ID from display name (GIDs are limited to 64 characters in database)
|
||||
*/
|
||||
private function computeGid(string $displayName): string {
|
||||
$displayNameWithoutWhitespace = preg_replace('/\s+/', '_', $displayName);
|
||||
return mb_strlen($displayNameWithoutWhitespace) > 64
|
||||
? hash('sha256', $displayNameWithoutWhitespace)
|
||||
: $displayNameWithoutWhitespace;
|
||||
return mb_strlen($displayName) > 64
|
||||
? hash('sha256', $displayName)
|
||||
: $displayName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,17 +57,4 @@ class DatabaseTest extends Backend {
|
|||
$group = $this->backend->getGroupDetails($gidCreated);
|
||||
$this->assertEquals(['displayName' => $groupName], $group);
|
||||
}
|
||||
|
||||
public function testWhiteSpaceInGroupName(): void {
|
||||
$randomId = $this->getUniqueID('test_', 10);
|
||||
$groupName = " group name with weird spaces \n" . $randomId;
|
||||
$expectedGroupName = 'group name with weird spaces ' . $randomId;
|
||||
$expectedGroupId = 'group_name_with_weird_spaces_' . $randomId;
|
||||
|
||||
$gidCreated = $this->backend->createGroup($groupName);
|
||||
$this->assertEquals($expectedGroupId, $gidCreated);
|
||||
|
||||
$group = $this->backend->getGroupDetails($gidCreated);
|
||||
$this->assertEquals(['displayName' => $expectedGroupName], $group);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue