🐛: … 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

2
Cargo.lock generated
View File

@@ -1283,7 +1283,7 @@ dependencies = [
[[package]] [[package]]
name = "oolatoocs" name = "oolatoocs"
version = "3.0.1" version = "3.0.2"
dependencies = [ dependencies = [
"atrium-api", "atrium-api",
"bsky-sdk", "bsky-sdk",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "oolatoocs" name = "oolatoocs"
version = "3.0.1" version = "3.0.2"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -38,11 +38,13 @@ pub async fn build_post_record(
while let Some(found) = re.captures(&rt.text.clone()) { while let Some(found) = re.captures(&rt.text.clone()) {
if let Some(group) = found.get(3) { if let Some(group) = found.get(3) {
rt.insert(group.start(), insert_chars); if !group.is_empty() {
rt.delete( rt.insert(group.start(), insert_chars);
group.start() + insert_chars.len(), rt.delete(
group.start() + insert_chars.len() + group.len(), group.start() + insert_chars.len(),
); group.start() + insert_chars.len() + group.len(),
);
}
} }
if let Some(group) = found.get(1) { if let Some(group) = found.get(1) {
rt.delete(group.start(), group.start() + group.len()); rt.delete(group.start(), group.start() + group.len());
@@ -195,8 +197,8 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_build_post_record() { 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 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…"; 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 { let bsky_conf = BlueskyConfig {
handle: "tamerelol.bsky.social".to_string(), handle: "tamerelol.bsky.social".to_string(),