Skip to content

Commit f9d566f

Browse files
committed
fix: Color/Name::from_str()` won't panic when encountering unicode values.
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.
1 parent 3f4db4a commit f9d566f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

gix-config-value/src/color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl FromStr for Name {
204204
}
205205

206206
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) {
208208
let rgb = (
209209
u8::from_str_radix(&s[..2], 16),
210210
u8::from_str_radix(&s[2..4], 16),

gix-config-value/tests/value/color.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ mod name {
5454
assert!(Name::from_str("#").is_err());
5555
assert!(Name::from_str("#fff").is_err());
5656
assert!(Name::from_str("#gggggg").is_err());
57+
assert!(Name::from_str("#=»©=").is_err());
5758
}
5859
}
5960

0 commit comments

Comments
 (0)