1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: allow you to add spaces to role descriptions (#8475)

This fixes a bug where we didn't allow spaces in role descriptions.
The bug came about because we wanted to disallow empty descriptions,
but that means we need to trim them before validating, not necessarily
before setting it.

However, that does mean that you can have descriptions with leading
and trailing spaces now, but that's probably fine.

To fix this, we'd have to do the trimming of the description only at
submission time, I think.
This commit is contained in:
Thomas Heartman 2024-10-18 11:07:06 +02:00 committed by GitHub
parent 9f0c438f36
commit 88f396f6b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 5 deletions

View File

@ -14,14 +14,14 @@ describe('trim names and description', () => {
expect(result.current.name).toBe('my role'); expect(result.current.name).toBe('my role');
}); });
test('description is trimmed before being set', () => { test('description is not trimmed before being set', () => {
const { result } = renderHook(() => useRoleForm()); const { result } = renderHook(() => useRoleForm());
act(() => { act(() => {
result.current.setDescription(' my description '); result.current.setDescription(' my description ');
}); });
expect(result.current.description).toBe('my description'); expect(result.current.description).toBe(' my description ');
}); });
test('name that is just whitespace triggers an error', () => { test('name that is just whitespace triggers an error', () => {

View File

@ -29,8 +29,6 @@ export const useRoleForm = (
const [name, setName] = useState(initialName); const [name, setName] = useState(initialName);
const setTrimmedName = (newName: string) => setName(newName.trim()); const setTrimmedName = (newName: string) => setName(newName.trim());
const [description, setDescription] = useState(initialDescription); const [description, setDescription] = useState(initialDescription);
const setTrimmedDescription = (newDescription: string) =>
setDescription(newDescription.trim());
const [checkedPermissions, setCheckedPermissions] = const [checkedPermissions, setCheckedPermissions] =
useState<ICheckedPermissions>({}); useState<ICheckedPermissions>({});
const [errors, setErrors] = useState<IRoleFormErrors>(DEFAULT_ERRORS); const [errors, setErrors] = useState<IRoleFormErrors>(DEFAULT_ERRORS);
@ -147,7 +145,7 @@ export const useRoleForm = (
setName: setTrimmedName, setName: setTrimmedName,
validateName, validateName,
description, description,
setDescription: setTrimmedDescription, setDescription,
validateDescription, validateDescription,
checkedPermissions, checkedPermissions,
setCheckedPermissions, setCheckedPermissions,