From 4188b6d2f2d0e408c8fdd86049d9d98a10eb4e75 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Tue, 21 Jun 2022 10:38:59 +0100 Subject: [PATCH] fix: ignore anchor links when parsing messages fixes #183 --- crates/quark/src/types/january.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/quark/src/types/january.rs b/crates/quark/src/types/january.rs index 8c3ce44f..24aca7dc 100644 --- a/crates/quark/src/types/january.rs +++ b/crates/quark/src/types/january.rs @@ -202,12 +202,22 @@ impl Embed { let mut finder = LinkFinder::new(); finder.kinds(&[LinkKind::Url]); - let links: HashSet = finder + // Process all links, stripping anchors and + // only taking up to `max_embeds` of links. + let links: Vec = finder .links(&content) + .map(|x| { + x.as_str() + .chars() + .take_while(|&ch| ch != '#') + .collect::() + }) + .collect::>() + .into_iter() .take(max_embeds) - .map(|x| x.as_str().to_string()) .collect(); + // If no links, fail out. if links.is_empty() { return Err(Error::LabelMe); }