Skip to content

Commit b67a2dd

Browse files
committed
hashtag: improve sanitization function
We don't want punctuation in hashtags Signed-off-by: William Casarin <[email protected]>
1 parent f214e97 commit b67a2dd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/notedeck_columns/src/ui/add_column.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,10 @@ pub fn hashtag_ui(
776776

777777
if handle_user_input && !text_buffer.is_empty() {
778778
let resp = AddColumnResponse::Timeline(TimelineKind::Hashtag(
779-
sanitize_hashtag(text_buffer)
779+
text_buffer
780780
.split_whitespace()
781781
.filter(|s| !s.is_empty())
782-
.map(|s| s.to_lowercase().to_string())
782+
.map(|s| sanitize_hashtag(s).to_lowercase().to_string())
783783
.collect::<Vec<_>>(),
784784
));
785785
id_string_map.remove(&id);
@@ -792,7 +792,10 @@ pub fn hashtag_ui(
792792
}
793793

794794
fn sanitize_hashtag(raw_hashtag: &str) -> String {
795-
raw_hashtag.replace("#", "")
795+
raw_hashtag
796+
.chars()
797+
.filter(|c| c.is_alphanumeric()) // keep letters and numbers only
798+
.collect()
796799
}
797800

798801
#[cfg(test)]

0 commit comments

Comments
 (0)