Add support for OPML 1.0 and 1.1.

This commit is contained in:
Bauke 2020-05-27 14:11:42 +02:00
parent 769e566414
commit 3e90b069a5
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
4 changed files with 7 additions and 19 deletions

View File

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

View File

@ -1,6 +1,6 @@
# OPML
> An OPML 2.0 parser for Rust.
> An OPML parser for Rust.
## Contents

View File

@ -88,12 +88,14 @@ impl OPML {
Err(err) => return Err(format!("XML parsing error: {:#?}", err)),
};
// TODO: Maybe implement version 1.0 and 1.1 of the OPML spec?
let version = &opml.version;
// SPEC: The version attribute is a version string, of the form, x.y, where x and y are both numeric strings.
let valid_version_regex = Regex::new(r"^\d+\.\d+$").unwrap();
let valid_versions = vec!["1.0", "1.1", "2.0"];
if !valid_version_regex.is_match(opml.version.as_str())
|| opml.version != "2.0"
if !valid_version_regex.is_match(version)
|| !valid_versions.contains(&version.as_str())
{
return Err(format!(
"Unsupported OPML version detected: {}",

View File

@ -9,20 +9,6 @@ fn test_invalid_xml() {
OPML::new(sample.as_str()).unwrap();
}
#[test]
#[should_panic(expected = "Unsupported OPML version detected: 1.0")]
fn test_invalid_opml_version_1_0() {
let sample = read("tests/samples/invalid_opml_version_1_0.opml").unwrap();
OPML::new(sample.as_str()).unwrap();
}
#[test]
#[should_panic(expected = "Unsupported OPML version detected: 1.1")]
fn test_invalid_opml_version_1_1() {
let sample = read("tests/samples/invalid_opml_version_1_1.opml").unwrap();
OPML::new(sample.as_str()).unwrap();
}
#[test]
#[should_panic(expected = "Unsupported OPML version detected: invalid")]
fn test_invalid_opml_version() {