|
|
@ -122,11 +122,12 @@ static RE_ANNOUNCE: once_cell::sync::Lazy<Regex> = |
|
|
|
Lazy::new(|| Regex::new(concat!(r"(?:^|\s|>|\n)[\\/]announce\s+(.*)$")).unwrap()); |
|
|
|
Lazy::new(|| Regex::new(concat!(r"(?:^|\s|>|\n)[\\/]announce\s+(.*)$")).unwrap()); |
|
|
|
|
|
|
|
|
|
|
|
static RE_A_HASHTAG: once_cell::sync::Lazy<Regex> = |
|
|
|
static RE_A_HASHTAG: once_cell::sync::Lazy<Regex> = |
|
|
|
Lazy::new(|| Regex::new(concat!(r"\b#(\w+)")).unwrap()); |
|
|
|
Lazy::new(|| Regex::new(concat!(r"(?:^|\b|\s|>|\n)#(\w+)")).unwrap()); |
|
|
|
|
|
|
|
|
|
|
|
pub fn parse_status_tags(content: &str) -> Vec<String> { |
|
|
|
pub fn parse_status_tags(content: &str) -> Vec<String> { |
|
|
|
debug!("Raw content: {}", content); |
|
|
|
debug!("Raw content: {}", content); |
|
|
|
let content = content.replace("<br/>", " "); |
|
|
|
let content = content.replace("<br/>", "<br/> "); |
|
|
|
|
|
|
|
let content = content.replace("</p>", "</p> "); |
|
|
|
let content = voca_rs::strip::strip_tags(&content); |
|
|
|
let content = voca_rs::strip::strip_tags(&content); |
|
|
|
debug!("Stripped tags: {}", content); |
|
|
|
debug!("Stripped tags: {}", content); |
|
|
|
|
|
|
|
|
|
|
@ -143,10 +144,8 @@ pub fn parse_status_tags(content: &str) -> Vec<String> { |
|
|
|
pub fn parse_slash_commands(content: &str) -> Vec<StatusCommand> { |
|
|
|
pub fn parse_slash_commands(content: &str) -> Vec<StatusCommand> { |
|
|
|
debug!("Raw content: {}", content); |
|
|
|
debug!("Raw content: {}", content); |
|
|
|
|
|
|
|
|
|
|
|
let content = content.replace("<br/>", " "); |
|
|
|
let content = content.replace("<br/>", "<br/> "); |
|
|
|
// let content = content.replace("<br />", " ");
|
|
|
|
let content = content.replace("</p>", "</p> "); |
|
|
|
// let content = content.replace("<BR/>", " ");
|
|
|
|
|
|
|
|
// let content = content.replace("<BR />", " ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let content = voca_rs::strip::strip_tags(&content); |
|
|
|
let content = voca_rs::strip::strip_tags(&content); |
|
|
|
debug!("Stripped tags: {}", content); |
|
|
|
debug!("Stripped tags: {}", content); |
|
|
@ -423,13 +422,14 @@ mod test { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_add_member() { |
|
|
|
fn test_add_tag() { |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #breadposting")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #breadposting")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #čučkaři")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #čučkaři")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #χαλβάς")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #χαλβάς")); |
|
|
|
assert!(RE_ADD_TAG.is_match("\\add #ласточка")); |
|
|
|
assert!(RE_ADD_TAG.is_match("\\add #ласточка")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #nya.")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #nya.")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #nya)")); |
|
|
|
assert!(RE_ADD_TAG.is_match("/add #nya)")); |
|
|
|
|
|
|
|
assert!(RE_ADD_TAG.is_match("/add #nya and more)")); |
|
|
|
|
|
|
|
|
|
|
|
let c = RE_ADD_TAG.captures("/add #breadposting"); |
|
|
|
let c = RE_ADD_TAG.captures("/add #breadposting"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "breadposting"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "breadposting"); |
|
|
@ -440,10 +440,10 @@ mod test { |
|
|
|
let c = RE_ADD_TAG.captures("/add #ласточка"); |
|
|
|
let c = RE_ADD_TAG.captures("/add #ласточка"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "ласточка"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "ласточка"); |
|
|
|
|
|
|
|
|
|
|
|
let c = RE_ADD_TAG.captures("#nya."); |
|
|
|
let c = RE_ADD_TAG.captures("/add #nya."); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "nya"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "nya"); |
|
|
|
|
|
|
|
|
|
|
|
let c = RE_ADD_TAG.captures("#nya)"); |
|
|
|
let c = RE_ADD_TAG.captures("/add #nya)"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "nya"); |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "nya"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -510,7 +510,7 @@ mod test { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_members() { |
|
|
|
fn test_tags() { |
|
|
|
assert!(!RE_TAGS.is_match("/members")); |
|
|
|
assert!(!RE_TAGS.is_match("/members")); |
|
|
|
assert!(RE_TAGS.is_match("/hashtags")); |
|
|
|
assert!(RE_TAGS.is_match("/hashtags")); |
|
|
|
assert!(RE_TAGS.is_match("dsfsd /tags dfgd d")); |
|
|
|
assert!(RE_TAGS.is_match("dsfsd /tags dfgd d")); |
|
|
@ -524,10 +524,17 @@ mod test { |
|
|
|
assert!(RE_A_HASHTAG.is_match("#χαλβάς")); |
|
|
|
assert!(RE_A_HASHTAG.is_match("#χαλβάς")); |
|
|
|
assert!(RE_A_HASHTAG.is_match("foo #banana gfdfgd")); |
|
|
|
assert!(RE_A_HASHTAG.is_match("foo #banana gfdfgd")); |
|
|
|
|
|
|
|
|
|
|
|
let c = RE_GRANT_ADMIN.captures("foo #banana #χαλβάς #ласточка."); |
|
|
|
for (i, c) in RE_A_HASHTAG.captures_iter("foo #banana #χαλβάς #ласточка").enumerate() { |
|
|
|
assert_eq!(c.unwrap().get(1).unwrap().as_str(), "banana"); |
|
|
|
if i == 0 { |
|
|
|
assert_eq!(c.unwrap().get(2).unwrap().as_str(), "χαλβάς"); |
|
|
|
assert_eq!(c.get(1).unwrap().as_str(), "banana"); |
|
|
|
assert_eq!(c.unwrap().get(3).unwrap().as_str(), "ласточка"); |
|
|
|
} |
|
|
|
|
|
|
|
else if i == 1 { |
|
|
|
|
|
|
|
assert_eq!(c.get(1).unwrap().as_str(), "χαλβάς"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if i == 2 { |
|
|
|
|
|
|
|
assert_eq!(c.get(1).unwrap().as_str(), "ласточка"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
@ -540,7 +547,7 @@ mod test { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_leave() { |
|
|
|
fn test_join() { |
|
|
|
assert!(!RE_JOIN.is_match("/list")); |
|
|
|
assert!(!RE_JOIN.is_match("/list")); |
|
|
|
assert!(RE_JOIN.is_match("/join")); |
|
|
|
assert!(RE_JOIN.is_match("/join")); |
|
|
|
assert!(RE_JOIN.is_match("/join")); |
|
|
|
assert!(RE_JOIN.is_match("/join")); |
|
|
|