diff --git a/clippy.toml b/clippy.toml index 143b25bf..7ca73027 100644 --- a/clippy.toml +++ b/clippy.toml @@ -2,6 +2,7 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true allow-dbg-in-tests = true allow-panic-in-tests = true +allow-indexing-slicing-in-tests = true absolute-paths-max-segments = 4 [[disallowed-types]] diff --git a/src/atom.rs b/src/atom.rs index 098c6b26..2db5a24b 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -1,2 +1,2 @@ mod feed; -pub use feed::{ATOM_NAMESPACE, AtomId, Content, Entry, Feed, Link}; +pub use feed::Feed; diff --git a/src/atom/feed.rs b/src/atom/feed.rs index aa509a37..f84c31f5 100644 --- a/src/atom/feed.rs +++ b/src/atom/feed.rs @@ -18,7 +18,7 @@ use uuid::Uuid; use crate::{ db::{self, Bookmark}, response_error::ResponseError, - views::content::bookmark_title, + views::common::bookmark_title, }; /// XML namespace of the Atom syndication format. @@ -27,11 +27,9 @@ pub static ATOM_NAMESPACE: &str = "http://www.w3.org/2005/Atom"; /// Permanent, universally unique identifier of a feed or entry. /// /// Serialized as a [`urn:uuid`] IRI, which stays valid even when the -/// server's base URL changes. See [RFC 4287] for the requirements on -/// `atom:id`. +/// server's base URL changes. /// /// [`urn:uuid`]: https://www.rfc-editor.org/rfc/rfc8141 -/// [RFC 4287]: https://www.rfc-editor.org/rfc/rfc4287#section-4.2.6 #[derive(Debug, Clone)] pub struct AtomId(pub Uuid); @@ -141,6 +139,7 @@ impl Feed { .map(|l| Entry::from_link(l, base_url)) .filter_map(|e| e.ok()) .collect(); + Ok(Feed { xmlns: ATOM_NAMESPACE, id: AtomId(list.id), @@ -189,7 +188,6 @@ impl IntoResponse for Feed { /// /// [XML specification]: https://www.w3.org/TR/xml/#charsets fn remove_illegal_xml_chars(text: &mut String) { - /// Whether `character` is allowed in XML documents. fn is_legal_xml_char(character: char) -> bool { matches!( character, @@ -216,15 +214,15 @@ impl Entry { updated: bookmark.created_at, links: vec![ // Primary "external link" shown by feed readers - Link { - rel: "via", - href: base_url.join(&bookmark.show_path())?, - }, - // Secondary "external link" shown by feed readers Link { rel: "alternate", href: bookmark_url, }, + // Secondary "external link", shown only by some feed readers + Link { + rel: "via", + href: base_url.join(&bookmark.show_path())?, + }, ], content: None, }) @@ -327,7 +325,6 @@ mod tests { let xml = feed.to_xml()?; assert_eq!(xml.matches("").count(), 2); - assert!(xml.find("First") < xml.find("Second")); Ok(()) } @@ -336,11 +333,7 @@ mod tests { fn falls_back_to_generic_title() -> anyhow::Result<()> { let feed = feed_for(&[bookmark_link(None, "https://ties.pub/")?])?; - assert!( - feed.entries - .iter() - .all(|entry| entry.title == "Untitled Bookmark") - ); + assert_eq!(feed.entries[0].title, "Untitled Bookmark"); Ok(()) } @@ -357,9 +350,7 @@ mod tests { assert!(xml.contains( r#"<script>alert("xss & fun")</script> > 1 & 1"# )); - // The user-defined title cannot break out of the title element. assert!(!xml.contains("