Don't allow zero-space char in display name. Fixes #1317

This commit is contained in:
Dessalines 2021-04-01 14:09:53 -04:00
parent bf7558830f
commit 799ab94af3
2 changed files with 10 additions and 1 deletions

View file

@ -32,6 +32,12 @@ fn test_valid_register_username() {
fn test_valid_display_name() { fn test_valid_display_name() {
assert!(is_valid_display_name("hello @there")); assert!(is_valid_display_name("hello @there"));
assert!(!is_valid_display_name("@hello there")); assert!(!is_valid_display_name("@hello there"));
// Make sure zero-space with an @ doesn't work
assert!(!is_valid_display_name(&format!(
"{}@my name is",
'\u{200b}'
)));
} }
#[test] #[test]

View file

@ -109,7 +109,10 @@ pub fn is_valid_username(name: &str) -> bool {
// Can't do a regex here, reverse lookarounds not supported // Can't do a regex here, reverse lookarounds not supported
pub fn is_valid_display_name(name: &str) -> bool { pub fn is_valid_display_name(name: &str) -> bool {
!name.starts_with('@') && name.chars().count() >= 3 && name.chars().count() <= 20 !name.starts_with('@')
&& !name.starts_with('\u{200b}')
&& name.chars().count() >= 3
&& name.chars().count() <= 20
} }
pub fn is_valid_community_name(name: &str) -> bool { pub fn is_valid_community_name(name: &str) -> bool {