From 0a988b543990b19918936e75026e0367e2ef7f12 Mon Sep 17 00:00:00 2001 From: silverpill Date: Mon, 16 May 2022 17:46:06 +0000 Subject: [PATCH] Allow hashtags to be followed by colon or question mark --- src/models/posts/tags.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/models/posts/tags.rs b/src/models/posts/tags.rs index 9a4ec56..8946a9f 100644 --- a/src/models/posts/tags.rs +++ b/src/models/posts/tags.rs @@ -4,7 +4,7 @@ use crate::errors::ValidationError; use crate::frontend::get_tag_page_url; const HASHTAG_RE: &str = r"(?m)(?P^|\s)#(?P\S+)"; -const HASHTAG_SECONDARY_RE: &str = r"^(?P[0-9A-Za-z]+)(?P(\.|
|\.
)?)$"; +const HASHTAG_SECONDARY_RE: &str = r"^(?P[0-9A-Za-z]+)(?P[\.:?]?(
)?)$"; const HASHTAG_NAME_RE: &str = r"^\w+$"; /// Finds anything that looks like a hashtag @@ -69,7 +69,8 @@ mod tests { let text = concat!( "@user1@server1 some text #TestTag.\n", "#TAG1 #tag1 #test_underscore #test*special ", - "more text #tag2", + "more text #tag2:
\n", + "end with #tag3", ); let tags = find_tags(text); @@ -77,6 +78,7 @@ mod tests { "testtag", "tag1", "tag2", + "tag3", ]); } @@ -85,7 +87,8 @@ mod tests { let text = concat!( "@user1@server1 some text #TestTag.\n", "#TAG1 #tag1 #test_underscore #test*special ", - "more text #tag2", + "more text #tag2:
\n", + "end with #tag3", ); let tags = find_tags(text); let output = replace_tags(INSTANCE_URL, &text, &tags); @@ -94,7 +97,8 @@ mod tests { r#"@user1@server1 some text #TestTag."#, "\n", r#"#TAG1 #tag1 "#, r#"#test_underscore #test*special "#, - r#"more text #tag2"#, + r#"more text #tag2:
"#, "\n", + r#"end with #tag3"#, ); assert_eq!(output, expected_output); }