🐛: … was apposed to every link regardless of their length

This commit is contained in:
VC
2024-10-02 10:44:43 +02:00
parent e0d3667fb9
commit 4b4f9abe2f
3 changed files with 11 additions and 9 deletions

View File

@@ -38,11 +38,13 @@ pub async fn build_post_record(
while let Some(found) = re.captures(&rt.text.clone()) {
if let Some(group) = found.get(3) {
rt.insert(group.start(), insert_chars);
rt.delete(
group.start() + insert_chars.len(),
group.start() + insert_chars.len() + group.len(),
);
if !group.is_empty() {
rt.insert(group.start(), insert_chars);
rt.delete(
group.start() + insert_chars.len(),
group.start() + insert_chars.len() + group.len(),
);
}
}
if let Some(group) = found.get(1) {
rt.delete(group.start(), group.start() + group.len());
@@ -195,8 +197,8 @@ mod tests {
#[tokio::test]
async fn test_build_post_record() {
let text = "@factornews@piaille.fr Retrouvez-nous ici https://www.nintendojo.fr/articles/editos/le-mod-renovation-de-8bitdo-pour-manette-n64 et là https://www.nintendojo.fr/articles/analyses/vite-vu/vite-vu-morbid-the-lords-of-ire";
let expected_text = "@factornews@piaille.fr Retrouvez-nous ici www.nintendojo.fr/articles… et là www.nintendojo.fr/articles…";
let text = "@factornews@piaille.fr Retrouvez-nous ici https://www.nintendojo.fr/articles/editos/le-mod-renovation-de-8bitdo-pour-manette-n64 et là https://www.nintendojo.fr/articles/analyses/vite-vu/vite-vu-morbid-the-lords-of-ire et un lien très court http://vsl.ie/TaMere";
let expected_text = "@factornews@piaille.fr Retrouvez-nous ici www.nintendojo.fr/articles… et là www.nintendojo.fr/articles… et un lien très court vsl.ie/TaMere";
let bsky_conf = BlueskyConfig {
handle: "tamerelol.bsky.social".to_string(),