mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-24 10:27:00 -06:00
Merge #1164: Reject non-finite coordinates in control-channel ui.input (@Silvertree2010)
This commit is contained in:
@@ -336,7 +336,8 @@ pub fn handle(app: &mut FigApp, ctx: &Context, method: &str, p: &Value) -> Resul
|
||||
.ok_or("`events` required: [{move|down|up: [x, y]} | {key, shift?, alt?, cmd?} | {text} | {leave: true}]")?;
|
||||
let pos = |v: &Value| -> Option<egui::Pos2> {
|
||||
let a = v.as_array()?;
|
||||
Some(egui::pos2(a.first()?.as_f64()? as f32, a.get(1)?.as_f64()? as f32))
|
||||
let p = egui::pos2(a.first()?.as_f64()? as f32, a.get(1)?.as_f64()? as f32);
|
||||
p.is_finite().then_some(p)
|
||||
};
|
||||
let mut events = Vec::new();
|
||||
let mut pads = Vec::new();
|
||||
|
||||
@@ -90,3 +90,13 @@ fn window_captures_are_written_through_the_roots_or_returned() {
|
||||
});
|
||||
assert!(d.0.join("out/shot.png").is_file() && !d.0.join("outside/shot.png").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ui_input_rejects_non_finite_coordinates() {
|
||||
let (mut app, _d) = confined_app("input");
|
||||
for ev in [json!({"move": [1e300, 5]}), json!({"down": [5, 1e300]}), json!({"scroll": [1e300, 0]})] {
|
||||
let r = handle(&mut app, "ui.input", json!({"events": [ev]}));
|
||||
assert!(r.is_err(), "{ev}: {r:?}");
|
||||
}
|
||||
assert!(app.control_input.iter().all(|e| !matches!(e, egui::Event::PointerMoved(p) if !p.is_finite())));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user