Reject non-hex characters in Image Trace ignoreColor

Found while testing crates/ui-egui/src/panels/image_trace.rs:28-34 (ignore_color)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-29 08:44:45 +07:00
committed by bflatastic
co-authored by Claude Haiku 5.5
parent c2fb35b244
commit 26f9b7f80c
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ fn ignore_color(params: &Value) -> [u8; 3] {
let hex = params["ignoreColor"].as_str().unwrap_or("").trim_start_matches('#');
let channel = |i: usize| hex.get(i * 2..i * 2 + 2).and_then(|h| u8::from_str_radix(h, 16).ok());
match (hex.len(), channel(0), channel(1), channel(2)) {
(6, Some(r), Some(g), Some(b)) => [r, g, b],
(6, Some(r), Some(g), Some(b)) if hex.bytes().all(|b| b.is_ascii_hexdigit()) => [r, g, b],
_ => [255; 3],
}
}
@@ -782,3 +782,10 @@ fn panel_and_menu_draw_headless() {
out.textures_delta.clear();
}
}
#[test]
fn ignore_color_rejects_signs_in_hex() {
assert_eq!(ignore_color(&json!({"ignoreColor": "#+f+f+f"})), [255; 3]);
assert_eq!(ignore_color(&json!({"ignoreColor": "+0+0+0"})), [255; 3]);
assert_eq!(ignore_color(&json!({"ignoreColor": "#ff00ff"})), [255, 0, 255]);
}