From a9c0deac339b113986619f5b51a203a730b99f96 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 15 Aug 2020 12:33:20 +0200 Subject: [PATCH] Make the text attribute "technically optional" by giving it a default. Apparently in OPML 1.0 text attributes are not required, so this should make it work for all versions. --- Cargo.toml | 2 +- source/lib.rs | 3 ++- tests/samples/valid_opml_1_0.opml | 6 ++++++ tests/valid.rs | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/samples/valid_opml_1_0.opml diff --git a/Cargo.toml b/Cargo.toml index ef5f71c..1205e4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "opml" authors = ["Holllo "] -version = "0.2.3" +version = "0.2.4" license = "MIT OR Apache-2.0" description = "An OPML parser for Rust." repository = "https://git.holllo.cc/holllo/opml" diff --git a/source/lib.rs b/source/lib.rs index a498b5d..eba0691 100644 --- a/source/lib.rs +++ b/source/lib.rs @@ -273,8 +273,9 @@ pub struct Body { #[xml(tag = "outline")] pub struct Outline { /// Every outline element must have at least a text attribute, which is what is displayed when an outliner opens the OPML document. + /// Version 1.0 OPML documents may omit this attribute, so for compatibility and strictness this attribute is "technically optional" as it will be replaced by an empty String if it is omitted. /// Text attributes may contain encoded HTML markup. - #[xml(attr = "text")] + #[xml(default, attr = "text")] pub text: String, /// A string that indicates how the other attributes of the [Outline](struct.Outline.html) should be interpreted. diff --git a/tests/samples/valid_opml_1_0.opml b/tests/samples/valid_opml_1_0.opml new file mode 100644 index 0000000..dd54efb --- /dev/null +++ b/tests/samples/valid_opml_1_0.opml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/valid.rs b/tests/valid.rs index 6e2d7b2..27e559a 100644 --- a/tests/valid.rs +++ b/tests/valid.rs @@ -77,3 +77,21 @@ fn test_valid_opml_with_everything() { } ) } + +#[test] +fn test_valid_opml_1_0() { + assert_eq!( + OPML::new(&read("tests/samples/valid_opml_1_0.opml").unwrap()).unwrap(), + OPML { + version: "1.0".to_string(), + head: Some(Head::default()), + body: Body { + outlines: vec![Outline { + text: String::default(), + title: Some("Outline Title".to_string()), + ..Outline::default() + }] + }, + } + ); +}