commit b67a2ddc31717ad5a9d0c2545e1644b222d8a3e0
parent f214e9738204331b1f0fcc09a6b13db2fb653b00
Author: William Casarin <jb55@jb55.com>
Date: Tue, 24 Jun 2025 08:22:58 -0700
hashtag: improve sanitization function
We don't want punctuation in hashtags
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
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
@@ -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::<Vec<_>>(),
));
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)]