diff --git a/changelog.d/939.bugfix b/changelog.d/939.bugfix new file mode 100644 index 000000000..a4bbff780 --- /dev/null +++ b/changelog.d/939.bugfix @@ -0,0 +1 @@ +Strip hash of label colors consistently. \ No newline at end of file diff --git a/src/format_util.rs b/src/format_util.rs index dc11b7ffc..f4b50098d 100644 --- a/src/format_util.rs +++ b/src/format_util.rs @@ -23,14 +23,7 @@ pub struct MatrixMessageFormatResult { pub plain: String, } -fn parse_rgb(input_color: String) -> Result { - let color = if input_color.starts_with('#') { - let mut chars = input_color.chars(); - chars.next(); - String::from_iter(chars) - } else { - input_color - }; +fn parse_rgb(color: &str) -> Result { let chunk_size = match color.len() { 6 => 2, 3 => 1, @@ -70,6 +63,11 @@ fn parse_rgb(input_color: String) -> Result { Ok(rgb) } +/// Strip the `#` character at the start of the string, if present. +fn strip_hash(s: &str) -> &str { + s.strip_prefix('#').unwrap_or(s) +} + #[napi] pub fn format_labels(array: Vec) -> Result { let mut plain = String::new(); @@ -84,6 +82,7 @@ pub fn format_labels(array: Vec) -> Result