Previously it would try to byte-index a presumed ascii string to convert hex to RGB, which could panic if the string wasn't actually ascii. Now it validates that the characters to convert are actually on a character boundary.
Unified · Split
| @@ -204,7 +204,7 @@ impl FromStr for Name { · 203 unmodified lines | ||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | if let Some(s) = s.strip_prefix('#') { |
| 207 | − if s.len() == 6 { | |
| 207 | + if s.len() == 6 && s.is_char_boundary(2) && s.is_char_boundary(4) && s.is_char_boundary(6) { | |
| 208 | 208 | let rgb = ( |
| 209 | 209 | u8::from_str_radix(&s[..2], 16), |
| 210 | 210 | u8::from_str_radix(&s[2..4], 16), |
| @@ -54,6 +54,7 @@ mod name { · 53 unmodified lines | ||
| 54 | 54 | assert!(Name::from_str("#").is_err()); |
| 55 | 55 | assert!(Name::from_str("#fff").is_err()); |
| 56 | 56 | assert!(Name::from_str("#gggggg").is_err()); |
| 57 | + assert!(Name::from_str("#=»©=").is_err()); | |
| 57 | 58 | } |
| 58 | 59 | } |
| 59 | 60 | |