Properly allowing for spaces on usernames
The new username on SUBKJT contract allow for multiple spaces.
Below are some suggestions for fix an issue where the names are displayed with a %20 instead of a space.
When displaying names on the website I would suggest:
- Trim any spaces at the beginning of the sentence
- Trim any spaces at the end of the sentence
- Trim more than 1 pace in the middle.
So for example:
| Input on SUBJK form | Currently Renders as |
|---|---|
| "Andre Venancio" | Andre%20Venancio |
| " Andre Venancio " | %20%20Andre%20Venancio%20%20 |
| "Andre Venancio" | Andre%20%20Venancio |
You can solve the spaces being transformed to %20 by running either:
str.replace(/%20/g, " ") or decodeURI(str)
But that doesn't trim any extra apace in the beginning, not the end or the name, nor it does remove any double spaces in between the first and last name.
For that, I would suggest:
str.replace(/\s+/g, " ").
So the overall code would be
const trimName = (str) => {
return decodeURI(str).replace(/\s+/g, " ");
}
As for the %20 on the URL, thats probably the desired solution, however, I would consider substituting the %20 for a - or a _. So hicetnunc.xyz/andre-venancio instead of hicetnunc.xyz/andre%20venancio
I think the big issues that lead to deciding to render the %20 were impersonation and url conflicts. I haven't had time to fully think this through but there are probably some places where we can safely render a sanitized name but other places where we need to make it explicitly clear when there's an extra space. Users also probably shouldn't be relying on names as a validation method but I reckon they do