From 3e90b069a53da563d96a4bdc3fb920f570df128d Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 27 May 2020 14:11:42 +0200 Subject: [PATCH] Add support for OPML 1.0 and 1.1. --- Cargo.toml | 2 +- ReadMe.md | 2 +- source/lib.rs | 8 +++++--- tests/errors.rs | 14 -------------- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34fb5a9..f2fa4ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "opml" authors = ["Holllo "] -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" diff --git a/ReadMe.md b/ReadMe.md index 04f8c93..e279eb0 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,6 +1,6 @@ # OPML -> An OPML 2.0 parser for Rust. +> An OPML parser for Rust. ## Contents diff --git a/source/lib.rs b/source/lib.rs index a9c610f..3f7c64b 100644 --- a/source/lib.rs +++ b/source/lib.rs @@ -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: {}", diff --git a/tests/errors.rs b/tests/errors.rs index 0b1cdbe..e3265c5 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -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() {