From b67a2ddc31717ad5a9d0c2545e1644b222d8a3e0 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 24 Jun 2025 08:22:58 -0700 Subject: [PATCH] hashtag: improve sanitization function We don't want punctuation in hashtags Signed-off-by: William Casarin --- crates/notedeck_columns/src/ui/add_column.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/notedeck_columns/src/ui/add_column.rs b/crates/notedeck_columns/src/ui/add_column.rs index 6395910f..d26298d6 100644 --- a/crates/notedeck_columns/src/ui/add_column.rs +++ b/crates/notedeck_columns/src/ui/add_column.rs @@ -776,10 +776,10 @@ pub fn hashtag_ui( if handle_user_input && !text_buffer.is_empty() { let resp = AddColumnResponse::Timeline(TimelineKind::Hashtag( - sanitize_hashtag(text_buffer) + text_buffer .split_whitespace() .filter(|s| !s.is_empty()) - .map(|s| s.to_lowercase().to_string()) + .map(|s| sanitize_hashtag(s).to_lowercase().to_string()) .collect::>(), )); id_string_map.remove(&id); @@ -792,7 +792,10 @@ pub fn hashtag_ui( } fn sanitize_hashtag(raw_hashtag: &str) -> String { - raw_hashtag.replace("#", "") + raw_hashtag + .chars() + .filter(|c| c.is_alphanumeric()) // keep letters and numbers only + .collect() } #[cfg(test)]