codidact / qpixel

Q&A-based community knowledge-sharing software
https://codidact.com
GNU Affero General Public License v3.0
385 stars 68 forks source link

Prevent or mitigate extra whitespace in user names #1380

Open cellio opened 1 month ago

cellio commented 1 month ago

meta:291173

We have some users with names that begin or end with lots of spaces, and there are some with expanses of spaces in the middle. This leads to confusing rendering, as shown in the linked post. When we show last activity, a user card, a history entry, a comment, etc, the user name (and its extents) should be clear.

A code-only change would be to trim the user name anywhere it's displayed (ignoring blocks of whitespace in the middle for now), but I have the feeling there's lots of code that just calls "user.name" or whatever the property is, so that'd be a lot of call sites. I don't know how hard it is to fix it at the DB level and what error checking/handling we'd need to put around that. A change like that might also annoy the affected users. Possibly a compromise would be to add a "full name" field (or some such), displayed on the profile only, seeding that with the current user names and then trimming the existing names. Maybe there are better approaches. This requires more analysis.

ws909 commented 1 month ago

Suggestion: before submitting the username the user input to the database, strip trailing and leading spaces, and trim every other stream of whitespace in the username to a single space.

Run a script that performs this modification on every existing username in the database.