-
-
Notifications
You must be signed in to change notification settings - Fork 199
feat: automatically sanitise usernames on create/update #424
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: higgs01 <[email protected]>
Signed-off-by: higgs01 <[email protected]>
// sanitise homoglyphs | ||
let options = decancer::Options::default() | ||
.retain_capitalization(); | ||
let mut username = decancer::cure(&username, options).unwrap().to_string(); |
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.
let mut username = decancer::cure(&username, options).unwrap().to_string(); | |
let mut username = decancer::cure(username, options).unwrap().to_string(); |
if BLOCKED_USERNAME_PATTERNS.is_match(&username) { | ||
username = BLOCKED_USERNAME_PATTERNS.replace_all(&mut username, "").into_owned(); | ||
} |
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.
Running the regex twice seems redundant. replace_all has no performance hit if a match isn't found.
username.push_str(&"_".repeat(username_length_diff)) | ||
} | ||
|
||
(original_username != username, username) |
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.
returning a boolean here is strange considering its usages already hold the original name, and it can simply be checked out there.
Making the min length configurable would just be a matter of adding an entry into revolt_config's models and the built-in Revolt.toml, then calling |
Thanks for the review - I'll probably get to looking at it next week. |
Fixes #257
This PR contains the following:
display_name
is set to the username originally provided by the user_
1.6.2
to3.3.3
to facilitate preserving capitalisation on sanitisationIn the Issue it was mentioned that it might be a good idea to make the min-length of the username configurable. I left this out of this PR for now, since I don't see a nice was to do this. If you've got an Idea I'm open to suggestions.
While testing this I noticed that while creating/renaming a bot the username is updated in the UI only after reloading. I'm not quite shure as to where I'd have to fix this and would like some guidance so that I can fix that there so that the UX is consistent for normal and bot users.
Please make sure to check the following tasks before opening and submitting a PR