[librsvg: 18/25] stroke-dash-array: Handle the case where a comma would be followed up with another comma.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 18/25] stroke-dash-array: Handle the case where a comma would be followed up with another comma.
- Date: Fri, 2 Feb 2018 00:30:07 +0000 (UTC)
commit fac54f7bb16716fdc11ac039da24d0c4741ebbfd
Author: Jordan Petridis <jordanpetridis protonmail com>
Date: Wed Jan 31 16:05:21 2018 +0200
stroke-dash-array: Handle the case where a comma would be followed up with another comma.
.gitlab-ci.yml | 4 ++--
rust/src/length.rs | 21 ++++++++++++---------
rust/src/lib.rs | 1 +
3 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1ca612c..e7e53b3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -24,11 +24,11 @@ test:
- ./autogen.sh --enable-debug
- make check
after_script:
- - mkdir test_artifacts
+ - mkdir png_artifacts
- cp /tmp/*.png png_artifacts
artifacts:
when: on_failure
paths:
- tests/*.log
- - png_artifacts/
+ - png_artifacts
diff --git a/rust/src/length.rs b/rust/src/length.rs
index 0d658c0..d091aa6 100644
--- a/rust/src/length.rs
+++ b/rust/src/length.rs
@@ -2,6 +2,7 @@ use cssparser::{Parser, ParserInput, Token};
use glib_sys;
use glib::translate::*;
use libc;
+use regex::Regex;
use std::f64::consts::*;
use std::mem;
@@ -342,8 +343,15 @@ fn parse_dash_array(s: &str) -> Result<Vec<RsvgLength>, AttributeError> {
}
}
+ // TODO: Use lazy static to avoid constructing the regex on each function call.
+ let commas = Regex::new(r",\s*,").unwrap();
+
+ if commas.is_match(s) {
+ return Err(AttributeError::Parse(ParseError::new("expected number, found comma")));
+ }
+
// Values can be comma or whitespace separated.
- let dashes = s.split(',') // split at comma
+ s.split(',') // split at comma
// split at whitespace
.flat_map(|slice| slice.split_whitespace())
// parse it into an RsvgLength
@@ -351,14 +359,7 @@ fn parse_dash_array(s: &str) -> Result<Vec<RsvgLength>, AttributeError> {
// collect into a Result<Vec<T>, E>.
// it will short-circuit iteslf upon the first error encountered
// like if you returned from a for-loop
- .collect::<Result<Vec<_>, _>>()?;
-
- // This can occure when input is something like ",,,"
- if dashes.is_empty() {
- return Err(AttributeError::Parse(ParseError::new("parse error")));
- }
-
- Ok(dashes)
+ .collect::<Result<Vec<_>, _>>()
}
@@ -599,5 +600,7 @@ mod tests {
assert!(parse_dash_array(",,,").is_err());
// No trailling commas allowed, parse error
assert!(parse_dash_array("10,").is_err());
+ // A comma should be followed by a number
+ assert!(parse_dash_array("20,,10").is_err());
}
}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 8c6f1b6..4823049 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -11,6 +11,7 @@ extern crate libc;
extern crate itertools;
extern crate pango;
extern crate pango_sys;
+extern crate regex;
#[macro_use]
extern crate downcast_rs;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]