VALID_USERNAME_REGEX.is_match(name)
}
+// Can't do a regex here, reverse lookarounds not supported
+pub fn is_valid_preferred_username(preferred_username: &str) -> bool {
+ !preferred_username.starts_with("@") && preferred_username.len() >=3 && preferred_username.len() <= 20
+}
+
pub fn is_valid_community_name(name: &str) -> bool {
VALID_COMMUNITY_NAME_REGEX.is_match(name)
}
is_valid_community_name,
is_valid_post_title,
is_valid_username,
+ is_valid_preferred_username,
remove_slurs,
scrape_text_for_mentions,
slur_check,
assert!(!is_valid_username(""));
}
+ #[test]
+ fn test_valid_preferred_username() {
+ assert!(is_valid_preferred_username("hello @there"));
+ assert!(!is_valid_preferred_username("@hello there"));
+ }
+
#[test]
fn test_valid_community_name() {
assert!(is_valid_community_name("example"));
use lemmy_utils::{
generate_actor_keypair,
generate_random_string,
+ is_valid_preferred_username,
is_valid_username,
make_apub_endpoint,
naive_from_unix,
// The DB constraint should stop too many characters
let preferred_username = match &data.preferred_username {
- Some(preferred_username) => Some(preferred_username.to_owned()),
+ Some(preferred_username) => {
+ if !is_valid_preferred_username(preferred_username.trim()) {
+ return Err(APIError::err("invalid_username").into());
+ }
+ Some(preferred_username.trim().to_string())
+ }
None => read_user.preferred_username,
};
);
WebSocketService.Instance.getSite();
+ setupTippy();
}
get isCurrentUser() {
// Couldnt get a refresh working. This does for now.
location.reload();
}
- setupTippy();
}
get documentTitle(): string {
this,
this.handleUserSettingsPreferredUsernameChange
)}
+ pattern="^(?!@)(.+)$"
minLength={3}
maxLength={20}
/>