diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index f15c5ab45f..4a65cd9342 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -739,12 +739,15 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit { @bindThis public async clone(role: MiRole, moderator?: MiUser): Promise { - let newName = `${role.name} (cloned)`; + const suffix = ' (cloned)'; + let newName = role.name; - if (newName.length > 256) { - newName = newName.slice(0, 256); + if (newName.length > 256 - suffix.length) { + newName = newName.slice(0, 256 - suffix.length); } + newName += suffix; + return this.create({ ...role, name: newName, diff --git a/packages/backend/test/unit/RoleService.ts b/packages/backend/test/unit/RoleService.ts index 534556b056..5a643a6a2c 100644 --- a/packages/backend/test/unit/RoleService.ts +++ b/packages/backend/test/unit/RoleService.ts @@ -1025,7 +1025,7 @@ describe('RoleService', () => { expect(clonedRole).toBeDefined(); expect(clonedRole.id).not.toBe(role.id); - expect(clonedRole.name).toBe(`${role.name} (`); + expect(clonedRole.name.endsWith(' (cloned)')).toBeTruthy(); expect(clonedRole.name.length).toBe(256); }); });