From 8aa3b0668b9e7832b0542439c2cc55b75cd5690b Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Wed, 21 Oct 2026 01:43:02 +0200 Subject: [PATCH] Reject '+' signs in color picker hex field Found while testing crates/ui-egui/src/color_picker_ui.rs:94-102 (parse_hex) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/ui-egui/src/color_picker_ui.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/color_picker_ui.rs b/crates/ui-egui/src/color_picker_ui.rs index 19272a62ed..805ada3e9f 100644 --- a/crates/ui-egui/src/color_picker_ui.rs +++ b/crates/ui-egui/src/color_picker_ui.rs @@ -93,7 +93,8 @@ pub fn hex(c: [f32; 3]) -> String { pub fn parse_hex(s: &str) -> Option<[f32; 3]> { let h = s.trim().trim_start_matches('#'); - if h.len() != 6 { + // `from_str_radix` accepts a leading '+', so require plain hex digits first. + if h.len() != 6 || !h.bytes().all(|b| b.is_ascii_hexdigit()) { return None; } // `get`, not `[..]`: typed text may be multi-byte, and a byte range can split a character. @@ -1144,6 +1145,13 @@ mod tests { assert_eq!(parse_hex("#ff880"), None); } + #[test] + fn parse_hex_rejects_signs() { + assert_eq!(parse_hex("#+f+f+f"), None); + assert_eq!(parse_hex("+1+2+3"), None); + assert!(parse_hex("#0f0f0f").is_some()); + } + #[test] fn hsv_round_trips() { for c in [[1.0, 0.0, 0.0], [0.2, 0.6, 0.4], [0.5, 0.5, 0.5], [0.0, 0.0, 1.0], [0.9, 0.8, 0.1]] {