diff options
author | Vika <vika@fireburn.ru> | 2021-05-09 16:24:21 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2021-05-09 16:24:21 +0300 |
commit | af8d55312ef99357ab23608eef6bf7fa40635828 (patch) | |
tree | d22111ee0ec0afcc824645846785bbdb1c2d4c4f /src | |
parent | 31b01d56f0f7812ea0fbb45e5924ce4eb0de7383 (diff) | |
download | kittybox-af8d55312ef99357ab23608eef6bf7fa40635828.tar.zst |
Fixed parsing the reply context for webmentions if there is no webmention endpoint
Diffstat (limited to 'src')
-rw-r--r-- | src/micropub/post.rs | 20 |
1 files changed, 19 insertions, 1 deletions
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<S: Storage>(req: Request<ApplicationState<S>>, 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#"<link href="{url}" rel="webmention">"#).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 { @@ -494,6 +496,22 @@ 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; |