-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ui): trim leading and trailing whitespace in group names #3617
Conversation
@@ -22,7 +22,7 @@ function AddGroupsDialog({ setOpen }) { | |||
try { | |||
const res = await fetch('/api/groups', { | |||
method: 'POST', | |||
body: JSON.stringify({ name }), | |||
body: JSON.stringify({ name: name.trim() }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
Rather than trimming the name here and in the error you could do one setName(name.trim())
before the try/catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the initial approach I took but it has two major downsides.
The first is it doesn't provide immediate feedback to the user when entering leading whitespace so what they think they've inputted into the field is not what's actually being sent to the server. This is minor.
The second is useState
doesn't immediately update the state. React batches state updates so if the state is changed immediately before it's checked, the update may not yet have been updated. This is problematic since the state is being updated immediately before sent to the server so while the state may be trimmed, the value being sent is untrimmed (most likely).
2a1cff8
to
5afbc69
Compare
5afbc69
to
3dc2bf9
Compare
leading whitespaces are particularly problematic because it makes it possible to create group names that look empty, e.g. " ". a side effect is group names with " " (one whitespace) and " " (multple consecutive whitespaces) will cause a 409 Conflict on creation since the server trims inputs. non-leading or non-trailing whitespaces are left as is so it's possible to have repeats in t between other characters
3dc2bf9
to
f995c61
Compare
Summary
leading whitespaces are particularly problematic because it makes it possible to create group names that look empty, e.g. " ". a side effect is group names with " " (one whitespace) and " " (multple consecutive whitespaces) will cause a 409 Conflict on creation since the server trims inputs.
non-leading or non-trailing whitespaces are left as is so it's possible to have repeats in t between other characters