mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-21 11:41:00 +00:00
relay: fix processing of unicode tags
This commit is contained in:
parent
ed8d2c9e06
commit
eda7568ffe
1 changed files with 28 additions and 4 deletions
32
src/relay.rs
32
src/relay.rs
|
@ -54,10 +54,19 @@ impl Post<'_> {
|
|||
// Distribute hashtags that end in a date to
|
||||
// followers of the hashtag with the date
|
||||
// stripped. Example: #dd1302 -> #dd
|
||||
let first_trailing_digit = s.rfind(|c| ! char::is_digit(c, 10))
|
||||
.map(|first_trailing_digit| first_trailing_digit + 1)
|
||||
.unwrap_or(s.len());
|
||||
if first_trailing_digit > 0 && first_trailing_digit < s.len() {
|
||||
let mut first_trailing_digit = 0;
|
||||
let mut scanning_digits = false;
|
||||
for (pos, c) in s.char_indices() {
|
||||
if char::is_digit(c, 10) {
|
||||
if ! scanning_digits {
|
||||
first_trailing_digit = pos;
|
||||
scanning_digits = true;
|
||||
}
|
||||
} else {
|
||||
scanning_digits = false;
|
||||
}
|
||||
}
|
||||
if scanning_digits && first_trailing_digit > 0 {
|
||||
let tag = &s[..first_trailing_digit];
|
||||
let actor2 = actor::ActorKind::from_tag(tag);
|
||||
vec![actor1, actor2]
|
||||
|
@ -291,4 +300,19 @@ mod test {
|
|||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("dd".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_relay_kind_jp() {
|
||||
let post = Post {
|
||||
url: Some("http://example.com/post/1"),
|
||||
uri: "http://example.com/post/1",
|
||||
tags: Some(vec![Tag {
|
||||
name: "スコティッシュ・フォールド・ロングヘアー",
|
||||
}]),
|
||||
};
|
||||
let mut kinds = post.relay_target_kinds();
|
||||
assert_eq!(kinds.next(), Some(ActorKind::InstanceRelay("example.com".to_string())));
|
||||
assert_eq!(kinds.next(), Some(ActorKind::TagRelay("sukoteitusiyuhuorudoronguhea".to_string())));
|
||||
assert_eq!(kinds.next(), None);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue