From 799ab94af313f635dbe4547ea2f9a85c3124fd11 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 1 Apr 2021 14:09:53 -0400 Subject: [PATCH] Don't allow zero-space char in display name. Fixes #1317 --- crates/utils/src/test.rs | 6 ++++++ crates/utils/src/utils.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/utils/src/test.rs b/crates/utils/src/test.rs index 04abd4b7..754aa8c3 100644 --- a/crates/utils/src/test.rs +++ b/crates/utils/src/test.rs @@ -32,6 +32,12 @@ fn test_valid_register_username() { fn test_valid_display_name() { 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] diff --git a/crates/utils/src/utils.rs b/crates/utils/src/utils.rs index 931565b6..732ac2c8 100644 --- a/crates/utils/src/utils.rs +++ b/crates/utils/src/utils.rs @@ -109,7 +109,10 @@ pub fn is_valid_username(name: &str) -> bool { // Can't do a regex here, reverse lookarounds not supported 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 { -- 2.44.1