From 10c08e6a44dc7d12a8f2be8688d19e6060c0024d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 24 Aug 2020 00:41:48 +0100 Subject: [PATCH] fix --- src/global.rs | 1 - src/imports.rs | 2 ++ src/pieces.rs | 1 + src/spec.rs | 13 ++++++++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/global.rs b/src/global.rs index d4e605e9..5dbe0674 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1,7 +1,6 @@ #![allow(clippy::let_and_return)] use crate::imports::*; -use lazy_static::lazy_static; use std::sync::PoisonError; diff --git a/src/imports.rs b/src/imports.rs index 83d97b37..04698213 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -62,6 +62,8 @@ pub use index_vec::{define_index_type,index_vec,IndexVec,IndexSlice}; pub use vecdeque_stableix::StableIndexVecDeque; pub use fs2::FileExt; +pub use lazy_static::lazy_static; +pub use regex::Regex; pub use crate::global::*; pub use crate::gamestate::*; diff --git a/src/pieces.rs b/src/pieces.rs index 454c96b9..e0a41ecd 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -23,6 +23,7 @@ pub enum SVGProcessingError { WriteFail, NegativeDragraise, ImproperSizeSpec, + UnsupportedColourSpec, } display_as_debug!{SVGProcessingError} diff --git a/src/spec.rs b/src/spec.rs index cbbe7ca0..178682ce 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -128,7 +128,18 @@ mod implementation { type Error = SE; #[throws(SE)] fn try_from(spec: &ColourSpec) -> Colour { - // xxx check syntax + lazy_static! { + static ref RE: Regex = Regex::new(concat!( + r"^(?:", r"[[:alpha:]]{1,50}", + r"|", r"#[[:xdigit:]]{3}{1,2}", + r"|", r"(?:rgba?|hsla?)\([-.%\t 0-9]{1,50}\)", + r")$" + )).unwrap(); + } + let s = &spec.0; + if !RE.is_match(s) { + throw!(SVGProcessingError::UnsupportedColourSpec); + } spec.0.clone() } } -- 2.30.2