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.
This commit is contained in:
Bauke 2020-08-15 12:33:20 +02:00
parent 18c8284ba9
commit a9c0deac33
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
4 changed files with 27 additions and 2 deletions

View File

@ -3,7 +3,7 @@
[package] [package]
name = "opml" name = "opml"
authors = ["Holllo <helllo@holllo.cc>"] authors = ["Holllo <helllo@holllo.cc>"]
version = "0.2.3" version = "0.2.4"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "An OPML parser for Rust." description = "An OPML parser for Rust."
repository = "https://git.holllo.cc/holllo/opml" repository = "https://git.holllo.cc/holllo/opml"

View File

@ -273,8 +273,9 @@ pub struct Body {
#[xml(tag = "outline")] #[xml(tag = "outline")]
pub struct 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. /// 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. /// Text attributes may contain encoded HTML markup.
#[xml(attr = "text")] #[xml(default, attr = "text")]
pub text: String, pub text: String,
/// A string that indicates how the other attributes of the [Outline](struct.Outline.html) should be interpreted. /// A string that indicates how the other attributes of the [Outline](struct.Outline.html) should be interpreted.

View File

@ -0,0 +1,6 @@
<opml version="1.0">
<head/>
<body>
<outline title="Outline Title"/>
</body>
</opml>

View File

@ -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()
}]
},
}
);
}