From af8d55312ef99357ab23608eef6bf7fa40635828 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 May 2021 16:24:21 +0300 Subject: Fixed parsing the reply context for webmentions if there is no webmention endpoint --- src/micropub/post.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/micropub') diff --git a/src/micropub/post.rs b/src/micropub/post.rs index 9edde54..ce9e6fa 100644 --- a/src/micropub/post.rs +++ b/src/micropub/post.rs @@ -334,7 +334,9 @@ async fn post_process_new_post(req: Request>, po // A compliant parser's output format includes rels, // we could just find a Webmention one in there let pattern = easy_scraper::Pattern::new(r#""#).expect("Pattern for webmentions couldn't be parsed"); - let endpoint = &pattern.matches(&body)[0]["url"]; + let matches = pattern.matches(&body); + if matches.is_empty() { return None } + let endpoint = &matches[0]["url"]; if let Ok(endpoint) = url.join(endpoint) { Some((url, endpoint)) } else { None } }) .map(|(target, endpoint)| async move { @@ -493,6 +495,22 @@ pub async fn post_handler(mut req: Request>) -> mod tests { use super::*; + #[test] + fn test_no_replace_uid() { + let mf2 = json!({ + "type": ["h-card"], + "properties": { + "uid": ["https://fireburn.ru/"], + "name": ["Vika Nezrimaya"], + "note": ["A crazy programmer girl who wants some hugs"] + } + }); + + let (uid, normalized) = normalize_mf2(mf2.clone(), &User::new("https://fireburn.ru/", "https://quill.p3k.io/", "create update media")); + assert_eq!(normalized["properties"]["uid"][0], mf2["properties"]["uid"][0], "UID was replaced"); + assert_eq!(normalized["properties"]["uid"][0], uid, "Returned post location doesn't match UID"); + } + #[test] fn test_form_to_mf2() { use serde_urlencoded::from_str; -- cgit 1.4.1