[librsvg: 9/25] stroke-dasharray: Return an error if there is a trailling comma.



commit ce146bb8194a888ca9cade4d4e3fd49e75970e9a
Author: Jordan Petridis <jordanpetridis protonmail com>
Date:   Mon Jan 29 22:10:50 2018 +0200

    stroke-dasharray: Return an error if there is a trailling comma.

 rust/src/length.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/rust/src/length.rs b/rust/src/length.rs
index 16b5316..f9ba3c1 100644
--- a/rust/src/length.rs
+++ b/rust/src/length.rs
@@ -315,6 +315,13 @@ fn parse_dash_array(s: &str) -> Result<Vec<RsvgLength>, AttributeError> {
         return Err(AttributeError::Parse(ParseError::new("empty string")));
     }
 
+    // Read the last character, if it's a comma return an Error.
+    if let Some(c) = s.chars().last() {
+        if c == ',' {
+            return Err(AttributeError::Parse(ParseError::new("trailling comma")));
+        }
+    }
+
     // Values can be comma or whitespace separated.
     let dashes = s.split(',') // split at comma
         // split at whitespace
@@ -532,7 +539,6 @@ mod tests {
         assert_eq!(parse_dash_array("\t  \n     "), Err(AttributeError::Parse(ParseError::new("empty 
string"))));
         assert!(parse_dash_array(",,,").is_err());
         // No trailling commas allowed, parse error
-        // println!("{:?}", parse_dash_array("10,"));
-        // assert!(parse_dash_array("10,").is_err());
+        assert!(parse_dash_array("10,").is_err());
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]