about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/micropub/post.rs20
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;