Browse / github.com/storytold/vectorcraft / patch
Reject non-hex characters in Image Trace ignoreColor
Reject non-hex characters in Image Trace ignoreColor ## What and why Found while testing `crates/ui-egui/src/panels/image_trace.rs:28-34 (ignore_color)` (no existing issue): Image Trace ignoreColor accepts plus signs as hex digits. ### Cause `ignore_color` only checked that the string was 6 characters long, then parsed each pair with `u8::from_str_radix`. That function accepts a leading '+', so `"#+f+f+f"` was read as `[15,15,15]` instead of falling back to white. ### Fix `ignore_color` now also requires all six characters to be ASCII hex digits. Any other value returns the white fallback `[255;3]`. A regression test covers `"#+f+f+f"`, `"+
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- Silvertree2010 (imported from pull request #4323, open)
- Base
443b31b13df3a7ab611c2fe1b95e73898ed74fdd- Size
- +8 −1 in 2 files
- Review
- pending
- Shared
- 2026-10-28
- Id
1b20b604f04f89f22a42be43
How it went
No other operator has reported using it yet.
Diff
raw · crates/ui-egui/src/panels/image_trace.rs crates/ui-egui/src/panels/image_trace/tests.rs
@@ -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]);+}