mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-08 19:42:05 +00:00
Merge pull request #1778 from Silvertree2010/fix/h4878-node-create-vector-create-silent
Reject invalid entries in vector.create points instead of dropping them
This commit is contained in:
2 files changed
+17
-1
No files matched your search
@@ -302,7 +302,14 @@ pub fn create(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
(w, h, offset) = (shape.width, shape.height, shape.offset);
|
||||
} else if let Some(Value::Array(pts)) = get(p, "points") {
|
||||
let pts: Vec<Point> = pts.iter().filter_map(|v| Some(Point::new(f64_of(v.get(0)?)?, f64_of(v.get(1)?)?))).collect();
|
||||
let pts: Vec<Point> = pts
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let xy = v.as_array().filter(|a| a.len() == 2)?;
|
||||
Some(Point::new(f64_of(&xy[0])?, f64_of(&xy[1])?))
|
||||
})
|
||||
.collect::<Option<_>>()
|
||||
.ok_or_else(|| bad(cmd, "`points` entries must be numeric [x, y] pairs"))?;
|
||||
if pts.len() < 2 {
|
||||
return Err(bad(cmd, "`points` needs at least two [x, y] pairs"));
|
||||
}
|
||||
|
||||
@@ -378,3 +378,12 @@ fn the_text_on_a_path_tool_carries_a_fill_bound_through_fills() {
|
||||
let t = editing(&s).expect("typing starts on the path");
|
||||
assert_eq!(s.doc().unwrap().node(t).unwrap().bound, bound, "the fill keeps following its variable");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_point_is_rejected() {
|
||||
let mut s = Session::new();
|
||||
assert!(s.execute("vector.create", &json!({"points": [[0, 0], ["abc", 5], [100, 100]], "closed": false})).is_err());
|
||||
assert!(s.execute("vector.create", &json!({"points": [[0, 0], [1], [100, 100]]})).is_err());
|
||||
assert!(s.execute("vector.create", &json!({"points": [[0, 0], 7, [100, 100]]})).is_err());
|
||||
assert!(s.execute("vector.create", &json!({"points": [[0, 0], [50, 5], [100, 100]]})).is_ok());
|
||||
}
|
||||
Reference in new issue
Block a user