chiark / gitweb /
fix
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Aug 2020 23:41:48 +0000 (00:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Aug 2020 23:41:48 +0000 (00:41 +0100)
src/global.rs
src/imports.rs
src/pieces.rs
src/spec.rs

index d4e605e999d8eaf99f4d2bb9b5dd21b1f5eb72bb..5dbe06742684614ed7d950969955ca797186bdb8 100644 (file)
@@ -1,7 +1,6 @@
 #![allow(clippy::let_and_return)]
 
 use crate::imports::*;
-use lazy_static::lazy_static;
 
 use std::sync::PoisonError;
 
index 83d97b371201d6009eff5e8a90ca1720607047c1..0469821392b0b63ba19e159eaea31701d920a879 100644 (file)
@@ -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::*;
index 454c96b997bcc16a200cf3637f48f46db89e4c8b..e0a41ecddcf121742446d5d4e1351a307b244a39 100644 (file)
@@ -23,6 +23,7 @@ pub enum SVGProcessingError {
   WriteFail,
   NegativeDragraise,
   ImproperSizeSpec,
+  UnsupportedColourSpec,
 }
 
 display_as_debug!{SVGProcessingError}
index cbbe7ca072a9e1369ff2b6fd32dec4f295347016..178682ce5f6aa05dc19a1a05a57565ac98e43da1 100644 (file)
@@ -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()
     }
   }